<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - /usr/include/google/protobuf/repeated_field.h</title>
  <link rel="stylesheet" type="text/css" href="../../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../../index.html">top level</a> - <a href="index.html">usr/include/google/protobuf</a> - repeated_field.h<span style="font-size: 80%;"> (source / <a href="repeated_field.h.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">59</td>
            <td class="headerCovTableEntry">87</td>
            <td class="headerCovTableEntryLo">67.8 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:50:33</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">37</td>
            <td class="headerCovTableEntry">65</td>
            <td class="headerCovTableEntryLo">56.9 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : // Protocol Buffers - Google's data interchange format</a>
<span class="lineNum">       2 </span>            : // Copyright 2008 Google Inc.  All rights reserved.
<span class="lineNum">       3 </span>            : // https://developers.google.com/protocol-buffers/
<span class="lineNum">       4 </span>            : //
<span class="lineNum">       5 </span>            : // Redistribution and use in source and binary forms, with or without
<span class="lineNum">       6 </span>            : // modification, are permitted provided that the following conditions are
<span class="lineNum">       7 </span>            : // met:
<span class="lineNum">       8 </span>            : //
<span class="lineNum">       9 </span>            : //     * Redistributions of source code must retain the above copyright
<span class="lineNum">      10 </span>            : // notice, this list of conditions and the following disclaimer.
<span class="lineNum">      11 </span>            : //     * Redistributions in binary form must reproduce the above
<span class="lineNum">      12 </span>            : // copyright notice, this list of conditions and the following disclaimer
<span class="lineNum">      13 </span>            : // in the documentation and/or other materials provided with the
<span class="lineNum">      14 </span>            : // distribution.
<span class="lineNum">      15 </span>            : //     * Neither the name of Google Inc. nor the names of its
<span class="lineNum">      16 </span>            : // contributors may be used to endorse or promote products derived from
<span class="lineNum">      17 </span>            : // this software without specific prior written permission.
<span class="lineNum">      18 </span>            : //
<span class="lineNum">      19 </span>            : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
<span class="lineNum">      20 </span>            : // &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
<span class="lineNum">      21 </span>            : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
<span class="lineNum">      22 </span>            : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
<span class="lineNum">      23 </span>            : // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
<span class="lineNum">      24 </span>            : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
<span class="lineNum">      25 </span>            : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
<span class="lineNum">      26 </span>            : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
<span class="lineNum">      27 </span>            : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
<span class="lineNum">      28 </span>            : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
<span class="lineNum">      29 </span>            : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<span class="lineNum">      30 </span>            : 
<span class="lineNum">      31 </span>            : // Author: kenton@google.com (Kenton Varda)
<span class="lineNum">      32 </span>            : //  Based on original Protocol Buffers design by
<span class="lineNum">      33 </span>            : //  Sanjay Ghemawat, Jeff Dean, and others.
<span class="lineNum">      34 </span>            : //
<span class="lineNum">      35 </span>            : // RepeatedField and RepeatedPtrField are used by generated protocol message
<span class="lineNum">      36 </span>            : // classes to manipulate repeated fields.  These classes are very similar to
<span class="lineNum">      37 </span>            : // STL's vector, but include a number of optimizations found to be useful
<span class="lineNum">      38 </span>            : // specifically in the case of Protocol Buffers.  RepeatedPtrField is
<span class="lineNum">      39 </span>            : // particularly different from STL vector as it manages ownership of the
<span class="lineNum">      40 </span>            : // pointers that it contains.
<span class="lineNum">      41 </span>            : //
<span class="lineNum">      42 </span>            : // Typically, clients should not need to access RepeatedField objects directly,
<span class="lineNum">      43 </span>            : // but should instead use the accessor functions generated automatically by the
<span class="lineNum">      44 </span>            : // protocol compiler.
<span class="lineNum">      45 </span>            : 
<span class="lineNum">      46 </span>            : #ifndef GOOGLE_PROTOBUF_REPEATED_FIELD_H__
<span class="lineNum">      47 </span>            : #define GOOGLE_PROTOBUF_REPEATED_FIELD_H__
<span class="lineNum">      48 </span>            : 
<span class="lineNum">      49 </span>            : #ifdef _MSC_VER
<span class="lineNum">      50 </span>            : // This is required for min/max on VS2013 only.
<span class="lineNum">      51 </span>            : #include &lt;algorithm&gt;
<span class="lineNum">      52 </span>            : #endif
<span class="lineNum">      53 </span>            : 
<span class="lineNum">      54 </span>            : #include &lt;string&gt;
<span class="lineNum">      55 </span>            : #include &lt;iterator&gt;
<span class="lineNum">      56 </span>            : #include &lt;google/protobuf/stubs/common.h&gt;
<span class="lineNum">      57 </span>            : #include &lt;google/protobuf/stubs/type_traits.h&gt;
<span class="lineNum">      58 </span>            : #include &lt;google/protobuf/generated_message_util.h&gt;
<span class="lineNum">      59 </span>            : #include &lt;google/protobuf/message_lite.h&gt;
<span class="lineNum">      60 </span>            : 
<span class="lineNum">      61 </span>            : namespace google {
<span class="lineNum">      62 </span>            : 
<span class="lineNum">      63 </span>            : namespace upb {
<span class="lineNum">      64 </span>            : namespace google_opensource {
<span class="lineNum">      65 </span>            : class GMR_Handlers;
<span class="lineNum">      66 </span>            : }  // namespace google_opensource
<span class="lineNum">      67 </span>            : }  // namespace upb
<span class="lineNum">      68 </span>            : 
<span class="lineNum">      69 </span>            : namespace protobuf {
<span class="lineNum">      70 </span>            : 
<span class="lineNum">      71 </span>            : class Message;
<span class="lineNum">      72 </span>            : 
<span class="lineNum">      73 </span>            : namespace internal {
<span class="lineNum">      74 </span>            : 
<span class="lineNum">      75 </span>            : static const int kMinRepeatedFieldAllocationSize = 4;
<span class="lineNum">      76 </span>            : 
<span class="lineNum">      77 </span>            : // A utility function for logging that doesn't need any template types.
<span class="lineNum">      78 </span>            : void LogIndexOutOfBounds(int index, int size);
<span class="lineNum">      79 </span>            : 
<span class="lineNum">      80 </span>            : template &lt;typename Iter&gt;
<span class="lineNum">      81 </span>            : inline int CalculateReserve(Iter begin, Iter end, std::forward_iterator_tag) {
<span class="lineNum">      82 </span>            :   return std::distance(begin, end);
<span class="lineNum">      83 </span>            : }
<span class="lineNum">      84 </span>            : 
<span class="lineNum">      85 </span>            : template &lt;typename Iter&gt;
<span class="lineNum">      86 </span>            : inline int CalculateReserve(Iter begin, Iter end, std::input_iterator_tag) {
<span class="lineNum">      87 </span>            :   return -1;
<span class="lineNum">      88 </span>            : }
<span class="lineNum">      89 </span>            : 
<span class="lineNum">      90 </span>            : template &lt;typename Iter&gt;
<span class="lineNum">      91 </span>            : inline int CalculateReserve(Iter begin, Iter end) {
<span class="lineNum">      92 </span>            :   typedef typename std::iterator_traits&lt;Iter&gt;::iterator_category Category;
<span class="lineNum">      93 </span>            :   return CalculateReserve(begin, end, Category());
<span class="lineNum">      94 </span>            : }
<span class="lineNum">      95 </span>            : }  // namespace internal
<span class="lineNum">      96 </span>            : 
<span class="lineNum">      97 </span>            : 
<span class="lineNum">      98 </span>            : // RepeatedField is used to represent repeated fields of a primitive type (in
<span class="lineNum">      99 </span>            : // other words, everything except strings and nested Messages).  Most users will
<span class="lineNum">     100 </span>            : // not ever use a RepeatedField directly; they will use the get-by-index,
<span class="lineNum">     101 </span>            : // set-by-index, and add accessors that are generated for all repeated fields.
<span class="lineNum">     102 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     103 </span>            : class RepeatedField {
<span class="lineNum">     104 </span>            :  public:
<span class="lineNum">     105 </span>            :   RepeatedField();
<span class="lineNum">     106 </span>            :   RepeatedField(const RepeatedField&amp; other);
<span class="lineNum">     107 </span>            :   template &lt;typename Iter&gt;
<span class="lineNum">     108 </span>            :   RepeatedField(Iter begin, const Iter&amp; end);
<span class="lineNum">     109 </span>            :   ~RepeatedField();
<span class="lineNum">     110 </span>            : 
<span class="lineNum">     111 </span>            :   RepeatedField&amp; operator=(const RepeatedField&amp; other);
<span class="lineNum">     112 </span>            : 
<span class="lineNum">     113 </span>            :   bool empty() const;
<span class="lineNum">     114 </span>            :   int size() const;
<span class="lineNum">     115 </span>            : 
<span class="lineNum">     116 </span>            :   const Element&amp; Get(int index) const;
<span class="lineNum">     117 </span>            :   Element* Mutable(int index);
<span class="lineNum">     118 </span>            :   void Set(int index, const Element&amp; value);
<span class="lineNum">     119 </span>            :   void Add(const Element&amp; value);
<span class="lineNum">     120 </span>            :   Element* Add();
<span class="lineNum">     121 </span>            :   // Remove the last element in the array.
<span class="lineNum">     122 </span>            :   void RemoveLast();
<span class="lineNum">     123 </span>            : 
<span class="lineNum">     124 </span>            :   // Extract elements with indices in &quot;[start .. start+num-1]&quot;.
<span class="lineNum">     125 </span>            :   // Copy them into &quot;elements[0 .. num-1]&quot; if &quot;elements&quot; is not NULL.
<span class="lineNum">     126 </span>            :   // Caution: implementation also moves elements with indices [start+num ..].
<span class="lineNum">     127 </span>            :   // Calling this routine inside a loop can cause quadratic behavior.
<span class="lineNum">     128 </span>            :   void ExtractSubrange(int start, int num, Element* elements);
<span class="lineNum">     129 </span>            : 
<span class="lineNum">     130 </span>            :   void Clear();
<span class="lineNum">     131 </span>            :   void MergeFrom(const RepeatedField&amp; other);
<span class="lineNum">     132 </span>            :   void CopyFrom(const RepeatedField&amp; other);
<span class="lineNum">     133 </span>            : 
<span class="lineNum">     134 </span>            :   // Reserve space to expand the field to at least the given size.  If the
<span class="lineNum">     135 </span>            :   // array is grown, it will always be at least doubled in size.
<span class="lineNum">     136 </span>            :   void Reserve(int new_size);
<span class="lineNum">     137 </span>            : 
<span class="lineNum">     138 </span>            :   // Resize the RepeatedField to a new, smaller size.  This is O(1).
<span class="lineNum">     139 </span>            :   void Truncate(int new_size);
<span class="lineNum">     140 </span>            : 
<span class="lineNum">     141 </span>            :   void AddAlreadyReserved(const Element&amp; value);
<span class="lineNum">     142 </span>            :   Element* AddAlreadyReserved();
<span class="lineNum">     143 </span>            :   int Capacity() const;
<span class="lineNum">     144 </span>            : 
<span class="lineNum">     145 </span>            :   // Like STL resize.  Uses value to fill appended elements.
<span class="lineNum">     146 </span>            :   // Like Truncate() if new_size &lt;= size(), otherwise this is
<span class="lineNum">     147 </span>            :   // O(new_size - size()).
<span class="lineNum">     148 </span>            :   void Resize(int new_size, const Element&amp; value);
<span class="lineNum">     149 </span>            : 
<span class="lineNum">     150 </span>            :   // Gets the underlying array.  This pointer is possibly invalidated by
<span class="lineNum">     151 </span>            :   // any add or remove operation.
<span class="lineNum">     152 </span>            :   Element* mutable_data();
<span class="lineNum">     153 </span>            :   const Element* data() const;
<span class="lineNum">     154 </span>            : 
<span class="lineNum">     155 </span>            :   // Swap entire contents with &quot;other&quot;.
<span class="lineNum">     156 </span>            :   void Swap(RepeatedField* other);
<span class="lineNum">     157 </span>            : 
<span class="lineNum">     158 </span>            :   // Swap two elements.
<span class="lineNum">     159 </span>            :   void SwapElements(int index1, int index2);
<span class="lineNum">     160 </span>            : 
<span class="lineNum">     161 </span>            :   // STL-like iterator support
<span class="lineNum">     162 </span>            :   typedef Element* iterator;
<span class="lineNum">     163 </span>            :   typedef const Element* const_iterator;
<span class="lineNum">     164 </span>            :   typedef Element value_type;
<span class="lineNum">     165 </span>            :   typedef value_type&amp; reference;
<span class="lineNum">     166 </span>            :   typedef const value_type&amp; const_reference;
<span class="lineNum">     167 </span>            :   typedef value_type* pointer;
<span class="lineNum">     168 </span>            :   typedef const value_type* const_pointer;
<span class="lineNum">     169 </span>            :   typedef int size_type;
<span class="lineNum">     170 </span>            :   typedef ptrdiff_t difference_type;
<span class="lineNum">     171 </span>            : 
<span class="lineNum">     172 </span>            :   iterator begin();
<span class="lineNum">     173 </span>            :   const_iterator begin() const;
<span class="lineNum">     174 </span>            :   iterator end();
<span class="lineNum">     175 </span>            :   const_iterator end() const;
<span class="lineNum">     176 </span>            : 
<span class="lineNum">     177 </span>            :   // Reverse iterator support
<span class="lineNum">     178 </span>            :   typedef std::reverse_iterator&lt;const_iterator&gt; const_reverse_iterator;
<span class="lineNum">     179 </span>            :   typedef std::reverse_iterator&lt;iterator&gt; reverse_iterator;
<span class="lineNum">     180 </span>            :   reverse_iterator rbegin() {
<span class="lineNum">     181 </span>            :     return reverse_iterator(end());
<span class="lineNum">     182 </span>            :   }
<span class="lineNum">     183 </span>            :   const_reverse_iterator rbegin() const {
<span class="lineNum">     184 </span>            :     return const_reverse_iterator(end());
<span class="lineNum">     185 </span>            :   }
<span class="lineNum">     186 </span>            :   reverse_iterator rend() {
<span class="lineNum">     187 </span>            :     return reverse_iterator(begin());
<span class="lineNum">     188 </span>            :   }
<span class="lineNum">     189 </span>            :   const_reverse_iterator rend() const {
<span class="lineNum">     190 </span>            :     return const_reverse_iterator(begin());
<span class="lineNum">     191 </span>            :   }
<span class="lineNum">     192 </span>            : 
<span class="lineNum">     193 </span>            :   // Returns the number of bytes used by the repeated field, excluding
<span class="lineNum">     194 </span>            :   // sizeof(*this)
<span class="lineNum">     195 </span>            :   int SpaceUsedExcludingSelf() const;
<span class="lineNum">     196 </span>            : 
<span class="lineNum">     197 </span>            :  private:
<span class="lineNum">     198 </span>            :   static const int kInitialSize = 0;
<span class="lineNum">     199 </span>            : 
<span class="lineNum">     200 </span>            :   Element* elements_;
<span class="lineNum">     201 </span>            :   int      current_size_;
<span class="lineNum">     202 </span>            :   int      total_size_;
<span class="lineNum">     203 </span>            : 
<span class="lineNum">     204 </span>            :   // Move the contents of |from| into |to|, possibly clobbering |from| in the
<span class="lineNum">     205 </span>            :   // process.  For primitive types this is just a memcpy(), but it could be
<span class="lineNum">     206 </span>            :   // specialized for non-primitive types to, say, swap each element instead.
<span class="lineNum">     207 </span>            :   void MoveArray(Element to[], Element from[], int size);
<span class="lineNum">     208 </span>            : 
<span class="lineNum">     209 </span>            :   // Copy the elements of |from| into |to|.
<span class="lineNum">     210 </span>            :   void CopyArray(Element to[], const Element from[], int size);
<span class="lineNum">     211 </span>            : };
<span class="lineNum">     212 </span>            : 
<span class="lineNum">     213 </span>            : namespace internal {
<span class="lineNum">     214 </span>            : template &lt;typename It&gt; class RepeatedPtrIterator;
<span class="lineNum">     215 </span>            : template &lt;typename It, typename VoidPtr&gt; class RepeatedPtrOverPtrsIterator;
<span class="lineNum">     216 </span>            : }  // namespace internal
<span class="lineNum">     217 </span>            : 
<span class="lineNum">     218 </span>            : namespace internal {
<span class="lineNum">     219 </span>            : 
<span class="lineNum">     220 </span>            : // This is a helper template to copy an array of elements effeciently when they
<span class="lineNum">     221 </span>            : // have a trivial copy constructor, and correctly otherwise. This really
<span class="lineNum">     222 </span>            : // shouldn't be necessary, but our compiler doesn't optimize std::copy very
<span class="lineNum">     223 </span>            : // effectively.
<span class="lineNum">     224 </span>            : template &lt;typename Element,
<span class="lineNum">     225 </span>            :           bool HasTrivialCopy = has_trivial_copy&lt;Element&gt;::value&gt;
<span class="lineNum">     226 </span>            : struct ElementCopier {
<span class="lineNum">     227 </span>            :   void operator()(Element to[], const Element from[], int array_size);
<span class="lineNum">     228 </span>            : };
<span class="lineNum">     229 </span>            : 
<span class="lineNum">     230 </span>            : }  // namespace internal
<span class="lineNum">     231 </span>            : 
<span class="lineNum">     232 </span>            : namespace internal {
<span class="lineNum">     233 </span>            : 
<span class="lineNum">     234 </span>            : // This is the common base class for RepeatedPtrFields.  It deals only in void*
<span class="lineNum">     235 </span>            : // pointers.  Users should not use this interface directly.
<span class="lineNum">     236 </span>            : //
<span class="lineNum">     237 </span>            : // The methods of this interface correspond to the methods of RepeatedPtrField,
<span class="lineNum">     238 </span>            : // but may have a template argument called TypeHandler.  Its signature is:
<span class="lineNum">     239 </span>            : //   class TypeHandler {
<span class="lineNum">     240 </span>            : //    public:
<span class="lineNum">     241 </span>            : //     typedef MyType Type;
<span class="lineNum">     242 </span>            : //     static Type* New();
<span class="lineNum">     243 </span>            : //     static void Delete(Type*);
<span class="lineNum">     244 </span>            : //     static void Clear(Type*);
<span class="lineNum">     245 </span>            : //     static void Merge(const Type&amp; from, Type* to);
<span class="lineNum">     246 </span>            : //
<span class="lineNum">     247 </span>            : //     // Only needs to be implemented if SpaceUsedExcludingSelf() is called.
<span class="lineNum">     248 </span>            : //     static int SpaceUsed(const Type&amp;);
<span class="lineNum">     249 </span>            : //   };
<span class="lineNum">     250 </span>            : class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase {
<span class="lineNum">     251 </span>            :  protected:
<span class="lineNum">     252 </span>            :   // The reflection implementation needs to call protected methods directly,
<span class="lineNum">     253 </span>            :   // reinterpreting pointers as being to Message instead of a specific Message
<span class="lineNum">     254 </span>            :   // subclass.
<span class="lineNum">     255 </span>            :   friend class GeneratedMessageReflection;
<span class="lineNum">     256 </span>            : 
<span class="lineNum">     257 </span>            :   // ExtensionSet stores repeated message extensions as
<span class="lineNum">     258 </span>            :   // RepeatedPtrField&lt;MessageLite&gt;, but non-lite ExtensionSets need to
<span class="lineNum">     259 </span>            :   // implement SpaceUsed(), and thus need to call SpaceUsedExcludingSelf()
<span class="lineNum">     260 </span>            :   // reinterpreting MessageLite as Message.  ExtensionSet also needs to make
<span class="lineNum">     261 </span>            :   // use of AddFromCleared(), which is not part of the public interface.
<span class="lineNum">     262 </span>            :   friend class ExtensionSet;
<span class="lineNum">     263 </span>            : 
<span class="lineNum">     264 </span>            :   // To parse directly into a proto2 generated class, the upb class GMR_Handlers
<span class="lineNum">     265 </span>            :   // needs to be able to modify a RepeatedPtrFieldBase directly.
<span class="lineNum">     266 </span>            :   friend class LIBPROTOBUF_EXPORT upb::google_opensource::GMR_Handlers;
<span class="lineNum">     267 </span>            : 
<span class="lineNum">     268 </span>            :   RepeatedPtrFieldBase();
<span class="lineNum">     269 </span>            : 
<span class="lineNum">     270 </span>            :   // Must be called from destructor.
<span class="lineNum">     271 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     272 </span>            :   void Destroy();
<span class="lineNum">     273 </span>            : 
<span class="lineNum">     274 </span>            :   bool empty() const;
<span class="lineNum">     275 </span>            :   int size() const;
<span class="lineNum">     276 </span>            : 
<span class="lineNum">     277 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     278 </span>            :   const typename TypeHandler::Type&amp; Get(int index) const;
<span class="lineNum">     279 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     280 </span>            :   typename TypeHandler::Type* Mutable(int index);
<span class="lineNum">     281 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     282 </span>            :   typename TypeHandler::Type* Add();
<span class="lineNum">     283 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     284 </span>            :   void RemoveLast();
<span class="lineNum">     285 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     286 </span>            :   void Clear();
<span class="lineNum">     287 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     288 </span>            :   void MergeFrom(const RepeatedPtrFieldBase&amp; other);
<span class="lineNum">     289 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     290 </span>            :   void CopyFrom(const RepeatedPtrFieldBase&amp; other);
<span class="lineNum">     291 </span>            : 
<span class="lineNum">     292 </span>            :   void CloseGap(int start, int num) {
<span class="lineNum">     293 </span>            :     // Close up a gap of &quot;num&quot; elements starting at offset &quot;start&quot;.
<span class="lineNum">     294 </span>            :     for (int i = start + num; i &lt; allocated_size_; ++i)
<span class="lineNum">     295 </span>            :       elements_[i - num] = elements_[i];
<span class="lineNum">     296 </span>            :     current_size_ -= num;
<span class="lineNum">     297 </span>            :     allocated_size_ -= num;
<span class="lineNum">     298 </span>            :   }
<span class="lineNum">     299 </span>            : 
<span class="lineNum">     300 </span>            :   void Reserve(int new_size);
<span class="lineNum">     301 </span>            : 
<span class="lineNum">     302 </span>            :   int Capacity() const;
<span class="lineNum">     303 </span>            : 
<span class="lineNum">     304 </span>            :   // Used for constructing iterators.
<span class="lineNum">     305 </span>            :   void* const* raw_data() const;
<span class="lineNum">     306 </span>            :   void** raw_mutable_data() const;
<span class="lineNum">     307 </span>            : 
<span class="lineNum">     308 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     309 </span>            :   typename TypeHandler::Type** mutable_data();
<span class="lineNum">     310 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     311 </span>            :   const typename TypeHandler::Type* const* data() const;
<span class="lineNum">     312 </span>            : 
<span class="lineNum">     313 </span>            :   void Swap(RepeatedPtrFieldBase* other);
<span class="lineNum">     314 </span>            : 
<span class="lineNum">     315 </span>            :   void SwapElements(int index1, int index2);
<span class="lineNum">     316 </span>            : 
<span class="lineNum">     317 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     318 </span>            :   int SpaceUsedExcludingSelf() const;
<span class="lineNum">     319 </span>            : 
<span class="lineNum">     320 </span>            : 
<span class="lineNum">     321 </span>            :   // Advanced memory management --------------------------------------
<span class="lineNum">     322 </span>            : 
<span class="lineNum">     323 </span>            :   // Like Add(), but if there are no cleared objects to use, returns NULL.
<span class="lineNum">     324 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     325 </span>            :   typename TypeHandler::Type* AddFromCleared();
<span class="lineNum">     326 </span>            : 
<span class="lineNum">     327 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     328 </span>            :   void AddAllocated(typename TypeHandler::Type* value);
<span class="lineNum">     329 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     330 </span>            :   typename TypeHandler::Type* ReleaseLast();
<span class="lineNum">     331 </span>            : 
<span class="lineNum">     332 </span>            :   int ClearedCount() const;
<span class="lineNum">     333 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     334 </span>            :   void AddCleared(typename TypeHandler::Type* value);
<span class="lineNum">     335 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     336 </span>            :   typename TypeHandler::Type* ReleaseCleared();
<span class="lineNum">     337 </span>            : 
<span class="lineNum">     338 </span>            :  private:
<span class="lineNum">     339 </span>            :   static const int kInitialSize = 0;
<span class="lineNum">     340 </span>            : 
<span class="lineNum">     341 </span>            :   void** elements_;
<span class="lineNum">     342 </span>            :   int    current_size_;
<span class="lineNum">     343 </span>            :   int    allocated_size_;
<span class="lineNum">     344 </span>            :   int    total_size_;
<span class="lineNum">     345 </span>            : 
<span class="lineNum">     346 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     347 </span>            :   static inline typename TypeHandler::Type* cast(void* element) {
<span class="lineNum">     348 </span>            :     return reinterpret_cast&lt;typename TypeHandler::Type*&gt;(element);
<span class="lineNum">     349 </span>            :   }
<span class="lineNum">     350 </span>            :   template &lt;typename TypeHandler&gt;
<span class="lineNum">     351 </span>            :   static inline const typename TypeHandler::Type* cast(const void* element) {
<span class="lineNum">     352 </span>            :     return reinterpret_cast&lt;const typename TypeHandler::Type*&gt;(element);
<span class="lineNum">     353 </span>            :   }
<span class="lineNum">     354 </span>            : 
<span class="lineNum">     355 </span>            :   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPtrFieldBase);
<span class="lineNum">     356 </span>            : };
<span class="lineNum">     357 </span>            : 
<span class="lineNum">     358 </span>            : template &lt;typename GenericType&gt;
<span class="lineNum">     359 </span>            : class GenericTypeHandler {
<a name="360"><span class="lineNum">     360 </span>            :  public:</a>
<span class="lineNum">     361 </span>            :   typedef GenericType Type;
<span class="lineNum">     362 </span><span class="lineCov">        218 :   static GenericType* New() { return new GenericType; }</span>
<span class="lineNum">     363 </span><span class="lineCov">        262 :   static void Delete(GenericType* value) { delete value; }</span>
<span class="lineNum">     364 </span><span class="lineCov">         82 :   static void Clear(GenericType* value) { value-&gt;Clear(); }</span>
<span class="lineNum">     365 </span>            :   static void Merge(const GenericType&amp; from, GenericType* to) {
<span class="lineNum">     366 </span><span class="lineCov">        178 :     to-&gt;MergeFrom(from);</span>
<span class="lineNum">     367 </span>            :   }
<span class="lineNum">     368 </span>            :   static int SpaceUsed(const GenericType&amp; value) { return value.SpaceUsed(); }
<span class="lineNum">     369 </span>            :   static const Type&amp; default_instance() { return Type::default_instance(); }
<span class="lineNum">     370 </span>            : };
<span class="lineNum">     371 </span>            : 
<span class="lineNum">     372 </span>            : template &lt;&gt;
<span class="lineNum">     373 </span>            : inline void GenericTypeHandler&lt;MessageLite&gt;::Merge(
<span class="lineNum">     374 </span>            :     const MessageLite&amp; from, MessageLite* to) {
<span class="lineNum">     375 </span>            :   to-&gt;CheckTypeAndMergeFrom(from);
<span class="lineNum">     376 </span>            : }
<span class="lineNum">     377 </span>            : 
<span class="lineNum">     378 </span>            : template &lt;&gt;
<span class="lineNum">     379 </span>            : inline const MessageLite&amp; GenericTypeHandler&lt;MessageLite&gt;::default_instance() {
<span class="lineNum">     380 </span>            :   // Yes, the behavior of the code is undefined, but this function is only
<span class="lineNum">     381 </span>            :   // called when we're already deep into the world of undefined, because the
<span class="lineNum">     382 </span>            :   // caller called Get(index) out of bounds.
<span class="lineNum">     383 </span>            :   MessageLite* null = NULL;
<span class="lineNum">     384 </span>            :   return *null;
<span class="lineNum">     385 </span>            : }
<span class="lineNum">     386 </span>            : 
<span class="lineNum">     387 </span>            : template &lt;&gt;
<span class="lineNum">     388 </span>            : inline const Message&amp; GenericTypeHandler&lt;Message&gt;::default_instance() {
<span class="lineNum">     389 </span>            :   // Yes, the behavior of the code is undefined, but this function is only
<span class="lineNum">     390 </span>            :   // called when we're already deep into the world of undefined, because the
<span class="lineNum">     391 </span>            :   // caller called Get(index) out of bounds.
<span class="lineNum">     392 </span>            :   Message* null = NULL;
<span class="lineNum">     393 </span>            :   return *null;
<span class="lineNum">     394 </span>            : }
<span class="lineNum">     395 </span>            : 
<span class="lineNum">     396 </span>            : 
<span class="lineNum">     397 </span>            : // HACK:  If a class is declared as DLL-exported in MSVC, it insists on
<span class="lineNum">     398 </span>            : //   generating copies of all its methods -- even inline ones -- to include
<span class="lineNum">     399 </span>            : //   in the DLL.  But SpaceUsed() calls StringSpaceUsedExcludingSelf() which
<span class="lineNum">     400 </span>            : //   isn't in the lite library, therefore the lite library cannot link if
<span class="lineNum">     401 </span>            : //   StringTypeHandler is exported.  So, we factor out StringTypeHandlerBase,
<span class="lineNum">     402 </span>            : //   export that, then make StringTypeHandler be a subclass which is NOT
<span class="lineNum">     403 </span>            : //   exported.
<span class="lineNum">     404 </span>            : // TODO(kenton):  There has to be a better way.
<span class="lineNum">     405 </span>            : class LIBPROTOBUF_EXPORT StringTypeHandlerBase {
<span class="lineNum">     406 </span>            :  public:
<span class="lineNum">     407 </span>            :   typedef string Type;
<span class="lineNum">     408 </span>            :   static string* New();
<span class="lineNum">     409 </span>            :   static void Delete(string* value);
<span class="lineNum">     410 </span>            :   static void Clear(string* value) { value-&gt;clear(); }
<span class="lineNum">     411 </span>            :   static void Merge(const string&amp; from, string* to) { *to = from; }
<span class="lineNum">     412 </span>            :   static const Type&amp; default_instance() {
<span class="lineNum">     413 </span>            :     return ::google::protobuf::internal::GetEmptyString();
<span class="lineNum">     414 </span>            :   }
<span class="lineNum">     415 </span>            : };
<span class="lineNum">     416 </span>            : 
<span class="lineNum">     417 </span>            : class StringTypeHandler : public StringTypeHandlerBase {
<span class="lineNum">     418 </span>            :  public:
<span class="lineNum">     419 </span>            :   static int SpaceUsed(const string&amp; value)  {
<span class="lineNum">     420 </span>            :     return sizeof(value) + StringSpaceUsedExcludingSelf(value);
<span class="lineNum">     421 </span>            :   }
<span class="lineNum">     422 </span>            : };
<span class="lineNum">     423 </span>            : 
<span class="lineNum">     424 </span>            : 
<span class="lineNum">     425 </span>            : }  // namespace internal
<span class="lineNum">     426 </span>            : 
<span class="lineNum">     427 </span>            : // RepeatedPtrField is like RepeatedField, but used for repeated strings or
<span class="lineNum">     428 </span>            : // Messages.
<span class="lineNum">     429 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     430 </span>            : class RepeatedPtrField : public internal::RepeatedPtrFieldBase {
<span class="lineNum">     431 </span>            :  public:
<span class="lineNum">     432 </span>            :   RepeatedPtrField();
<span class="lineNum">     433 </span>            :   RepeatedPtrField(const RepeatedPtrField&amp; other);
<span class="lineNum">     434 </span>            :   template &lt;typename Iter&gt;
<span class="lineNum">     435 </span>            :   RepeatedPtrField(Iter begin, const Iter&amp; end);
<span class="lineNum">     436 </span>            :   ~RepeatedPtrField();
<span class="lineNum">     437 </span>            : 
<span class="lineNum">     438 </span>            :   RepeatedPtrField&amp; operator=(const RepeatedPtrField&amp; other);
<span class="lineNum">     439 </span>            : 
<span class="lineNum">     440 </span>            :   bool empty() const;
<span class="lineNum">     441 </span>            :   int size() const;
<span class="lineNum">     442 </span>            : 
<span class="lineNum">     443 </span>            :   const Element&amp; Get(int index) const;
<span class="lineNum">     444 </span>            :   Element* Mutable(int index);
<span class="lineNum">     445 </span>            :   Element* Add();
<span class="lineNum">     446 </span>            : 
<span class="lineNum">     447 </span>            :   // Remove the last element in the array.
<span class="lineNum">     448 </span>            :   // Ownership of the element is retained by the array.
<span class="lineNum">     449 </span>            :   void RemoveLast();
<span class="lineNum">     450 </span>            : 
<span class="lineNum">     451 </span>            :   // Delete elements with indices in the range [start .. start+num-1].
<span class="lineNum">     452 </span>            :   // Caution: implementation moves all elements with indices [start+num .. ].
<span class="lineNum">     453 </span>            :   // Calling this routine inside a loop can cause quadratic behavior.
<span class="lineNum">     454 </span>            :   void DeleteSubrange(int start, int num);
<span class="lineNum">     455 </span>            : 
<span class="lineNum">     456 </span>            :   void Clear();
<span class="lineNum">     457 </span>            :   void MergeFrom(const RepeatedPtrField&amp; other);
<span class="lineNum">     458 </span>            :   void CopyFrom(const RepeatedPtrField&amp; other);
<span class="lineNum">     459 </span>            : 
<span class="lineNum">     460 </span>            :   // Reserve space to expand the field to at least the given size.  This only
<span class="lineNum">     461 </span>            :   // resizes the pointer array; it doesn't allocate any objects.  If the
<span class="lineNum">     462 </span>            :   // array is grown, it will always be at least doubled in size.
<span class="lineNum">     463 </span>            :   void Reserve(int new_size);
<span class="lineNum">     464 </span>            : 
<span class="lineNum">     465 </span>            :   int Capacity() const;
<span class="lineNum">     466 </span>            : 
<span class="lineNum">     467 </span>            :   // Gets the underlying array.  This pointer is possibly invalidated by
<span class="lineNum">     468 </span>            :   // any add or remove operation.
<span class="lineNum">     469 </span>            :   Element** mutable_data();
<span class="lineNum">     470 </span>            :   const Element* const* data() const;
<span class="lineNum">     471 </span>            : 
<span class="lineNum">     472 </span>            :   // Swap entire contents with &quot;other&quot;.
<span class="lineNum">     473 </span>            :   void Swap(RepeatedPtrField* other);
<span class="lineNum">     474 </span>            : 
<span class="lineNum">     475 </span>            :   // Swap two elements.
<span class="lineNum">     476 </span>            :   void SwapElements(int index1, int index2);
<span class="lineNum">     477 </span>            : 
<span class="lineNum">     478 </span>            :   // STL-like iterator support
<span class="lineNum">     479 </span>            :   typedef internal::RepeatedPtrIterator&lt;Element&gt; iterator;
<span class="lineNum">     480 </span>            :   typedef internal::RepeatedPtrIterator&lt;const Element&gt; const_iterator;
<span class="lineNum">     481 </span>            :   typedef Element value_type;
<span class="lineNum">     482 </span>            :   typedef value_type&amp; reference;
<span class="lineNum">     483 </span>            :   typedef const value_type&amp; const_reference;
<span class="lineNum">     484 </span>            :   typedef value_type* pointer;
<span class="lineNum">     485 </span>            :   typedef const value_type* const_pointer;
<span class="lineNum">     486 </span>            :   typedef int size_type;
<span class="lineNum">     487 </span>            :   typedef ptrdiff_t difference_type;
<span class="lineNum">     488 </span>            : 
<span class="lineNum">     489 </span>            :   iterator begin();
<span class="lineNum">     490 </span>            :   const_iterator begin() const;
<span class="lineNum">     491 </span>            :   iterator end();
<span class="lineNum">     492 </span>            :   const_iterator end() const;
<span class="lineNum">     493 </span>            : 
<span class="lineNum">     494 </span>            :   // Reverse iterator support
<span class="lineNum">     495 </span>            :   typedef std::reverse_iterator&lt;const_iterator&gt; const_reverse_iterator;
<span class="lineNum">     496 </span>            :   typedef std::reverse_iterator&lt;iterator&gt; reverse_iterator;
<span class="lineNum">     497 </span>            :   reverse_iterator rbegin() {
<span class="lineNum">     498 </span>            :     return reverse_iterator(end());
<span class="lineNum">     499 </span>            :   }
<span class="lineNum">     500 </span>            :   const_reverse_iterator rbegin() const {
<span class="lineNum">     501 </span>            :     return const_reverse_iterator(end());
<span class="lineNum">     502 </span>            :   }
<span class="lineNum">     503 </span>            :   reverse_iterator rend() {
<span class="lineNum">     504 </span>            :     return reverse_iterator(begin());
<span class="lineNum">     505 </span>            :   }
<span class="lineNum">     506 </span>            :   const_reverse_iterator rend() const {
<span class="lineNum">     507 </span>            :     return const_reverse_iterator(begin());
<span class="lineNum">     508 </span>            :   }
<span class="lineNum">     509 </span>            : 
<span class="lineNum">     510 </span>            :   // Custom STL-like iterator that iterates over and returns the underlying
<span class="lineNum">     511 </span>            :   // pointers to Element rather than Element itself.
<span class="lineNum">     512 </span>            :   typedef internal::RepeatedPtrOverPtrsIterator&lt;Element, void*&gt;
<span class="lineNum">     513 </span>            :   pointer_iterator;
<span class="lineNum">     514 </span>            :   typedef internal::RepeatedPtrOverPtrsIterator&lt;const Element, const void*&gt;
<span class="lineNum">     515 </span>            :   const_pointer_iterator;
<span class="lineNum">     516 </span>            :   pointer_iterator pointer_begin();
<span class="lineNum">     517 </span>            :   const_pointer_iterator pointer_begin() const;
<span class="lineNum">     518 </span>            :   pointer_iterator pointer_end();
<span class="lineNum">     519 </span>            :   const_pointer_iterator pointer_end() const;
<span class="lineNum">     520 </span>            : 
<span class="lineNum">     521 </span>            :   // Returns (an estimate of) the number of bytes used by the repeated field,
<span class="lineNum">     522 </span>            :   // excluding sizeof(*this).
<span class="lineNum">     523 </span>            :   int SpaceUsedExcludingSelf() const;
<span class="lineNum">     524 </span>            : 
<span class="lineNum">     525 </span>            :   // Advanced memory management --------------------------------------
<span class="lineNum">     526 </span>            :   // When hardcore memory management becomes necessary -- as it sometimes
<span class="lineNum">     527 </span>            :   // does here at Google -- the following methods may be useful.
<span class="lineNum">     528 </span>            : 
<span class="lineNum">     529 </span>            :   // Add an already-allocated object, passing ownership to the
<span class="lineNum">     530 </span>            :   // RepeatedPtrField.
<span class="lineNum">     531 </span>            :   void AddAllocated(Element* value);
<span class="lineNum">     532 </span>            :   // Remove the last element and return it, passing ownership to the caller.
<span class="lineNum">     533 </span>            :   // Requires:  size() &gt; 0
<span class="lineNum">     534 </span>            :   Element* ReleaseLast();
<span class="lineNum">     535 </span>            : 
<span class="lineNum">     536 </span>            :   // Extract elements with indices in the range &quot;[start .. start+num-1]&quot;.
<span class="lineNum">     537 </span>            :   // The caller assumes ownership of the extracted elements and is responsible
<span class="lineNum">     538 </span>            :   // for deleting them when they are no longer needed.
<span class="lineNum">     539 </span>            :   // If &quot;elements&quot; is non-NULL, then pointers to the extracted elements
<span class="lineNum">     540 </span>            :   // are stored in &quot;elements[0 .. num-1]&quot; for the convenience of the caller.
<span class="lineNum">     541 </span>            :   // If &quot;elements&quot; is NULL, then the caller must use some other mechanism
<span class="lineNum">     542 </span>            :   // to perform any further operations (like deletion) on these elements.
<span class="lineNum">     543 </span>            :   // Caution: implementation also moves elements with indices [start+num ..].
<span class="lineNum">     544 </span>            :   // Calling this routine inside a loop can cause quadratic behavior.
<span class="lineNum">     545 </span>            :   void ExtractSubrange(int start, int num, Element** elements);
<span class="lineNum">     546 </span>            : 
<span class="lineNum">     547 </span>            :   // When elements are removed by calls to RemoveLast() or Clear(), they
<span class="lineNum">     548 </span>            :   // are not actually freed.  Instead, they are cleared and kept so that
<span class="lineNum">     549 </span>            :   // they can be reused later.  This can save lots of CPU time when
<span class="lineNum">     550 </span>            :   // repeatedly reusing a protocol message for similar purposes.
<span class="lineNum">     551 </span>            :   //
<span class="lineNum">     552 </span>            :   // Hardcore programs may choose to manipulate these cleared objects
<span class="lineNum">     553 </span>            :   // to better optimize memory management using the following routines.
<span class="lineNum">     554 </span>            : 
<span class="lineNum">     555 </span>            :   // Get the number of cleared objects that are currently being kept
<span class="lineNum">     556 </span>            :   // around for reuse.
<span class="lineNum">     557 </span>            :   int ClearedCount() const;
<span class="lineNum">     558 </span>            :   // Add an element to the pool of cleared objects, passing ownership to
<span class="lineNum">     559 </span>            :   // the RepeatedPtrField.  The element must be cleared prior to calling
<span class="lineNum">     560 </span>            :   // this method.
<span class="lineNum">     561 </span>            :   void AddCleared(Element* value);
<span class="lineNum">     562 </span>            :   // Remove a single element from the cleared pool and return it, passing
<span class="lineNum">     563 </span>            :   // ownership to the caller.  The element is guaranteed to be cleared.
<span class="lineNum">     564 </span>            :   // Requires:  ClearedCount() &gt; 0
<span class="lineNum">     565 </span>            :   Element* ReleaseCleared();
<span class="lineNum">     566 </span>            : 
<span class="lineNum">     567 </span>            :  protected:
<span class="lineNum">     568 </span>            :   // Note:  RepeatedPtrField SHOULD NOT be subclassed by users.  We only
<span class="lineNum">     569 </span>            :   //   subclass it in one place as a hack for compatibility with proto1.  The
<span class="lineNum">     570 </span>            :   //   subclass needs to know about TypeHandler in order to call protected
<span class="lineNum">     571 </span>            :   //   methods on RepeatedPtrFieldBase.
<span class="lineNum">     572 </span>            :   class TypeHandler;
<span class="lineNum">     573 </span>            : 
<span class="lineNum">     574 </span>            : };
<span class="lineNum">     575 </span>            : 
<span class="lineNum">     576 </span>            : // implementation ====================================================
<span class="lineNum">     577 </span>            : 
<span class="lineNum">     578 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     579 </span>            : inline RepeatedField&lt;Element&gt;::RepeatedField()
<span class="lineNum">     580 </span>            :   : elements_(NULL),
<span class="lineNum">     581 </span>            :     current_size_(0),
<span class="lineNum">     582 </span><span class="lineCov">      12525 :     total_size_(kInitialSize) {</span>
<span class="lineNum">     583 </span>            : }
<span class="lineNum">     584 </span>            : 
<span class="lineNum">     585 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     586 </span>            : inline RepeatedField&lt;Element&gt;::RepeatedField(const RepeatedField&amp; other)
<span class="lineNum">     587 </span>            :   : elements_(NULL),
<span class="lineNum">     588 </span>            :     current_size_(0),
<span class="lineNum">     589 </span>            :     total_size_(kInitialSize) {
<span class="lineNum">     590 </span>            :   CopyFrom(other);
<span class="lineNum">     591 </span>            : }
<span class="lineNum">     592 </span>            : 
<span class="lineNum">     593 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     594 </span>            : template &lt;typename Iter&gt;
<span class="lineNum">     595 </span>            : inline RepeatedField&lt;Element&gt;::RepeatedField(Iter begin, const Iter&amp; end)
<span class="lineNum">     596 </span>            :   : elements_(NULL),
<span class="lineNum">     597 </span>            :     current_size_(0),
<span class="lineNum">     598 </span>            :     total_size_(kInitialSize) {
<span class="lineNum">     599 </span>            :   int reserve = internal::CalculateReserve(begin, end);
<span class="lineNum">     600 </span>            :   if (reserve != -1) {
<span class="lineNum">     601 </span>            :     Reserve(reserve);
<span class="lineNum">     602 </span>            :     for (; begin != end; ++begin) {
<span class="lineNum">     603 </span>            :       AddAlreadyReserved(*begin);
<span class="lineNum">     604 </span>            :     }
<span class="lineNum">     605 </span>            :   } else {
<span class="lineNum">     606 </span>            :     for (; begin != end; ++begin) {
<span class="lineNum">     607 </span>            :       Add(*begin);
<span class="lineNum">     608 </span>            :     }
<span class="lineNum">     609 </span>            :   }
<span class="lineNum">     610 </span>            : }
<span class="lineNum">     611 </span>            : 
<span class="lineNum">     612 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     613 </span>            : RepeatedField&lt;Element&gt;::~RepeatedField() {
<span class="lineNum">     614 </span><span class="lineCov">      12722 :   delete [] elements_;</span>
<span class="lineNum">     615 </span><span class="lineCov">      12722 : }</span>
<span class="lineNum">     616 </span>            : 
<span class="lineNum">     617 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     618 </span>            : inline RepeatedField&lt;Element&gt;&amp;
<span class="lineNum">     619 </span>            : RepeatedField&lt;Element&gt;::operator=(const RepeatedField&amp; other) {
<span class="lineNum">     620 </span>            :   if (this != &amp;other)
<span class="lineNum">     621 </span>            :     CopyFrom(other);
<span class="lineNum">     622 </span>            :   return *this;
<span class="lineNum">     623 </span>            : }
<span class="lineNum">     624 </span>            : 
<span class="lineNum">     625 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     626 </span>            : inline bool RepeatedField&lt;Element&gt;::empty() const {
<span class="lineNum">     627 </span>            :   return current_size_ == 0;
<span class="lineNum">     628 </span>            : }
<span class="lineNum">     629 </span>            : 
<span class="lineNum">     630 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     631 </span>            : inline int RepeatedField&lt;Element&gt;::size() const {
<span class="lineNum">     632 </span>            :   return current_size_;
<span class="lineNum">     633 </span>            : }
<a name="634"><span class="lineNum">     634 </span>            : </a>
<span class="lineNum">     635 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     636 </span><span class="lineNoCov">          0 : inline int RepeatedField&lt;Element&gt;::Capacity() const {</span>
<span class="lineNum">     637 </span><span class="lineNoCov">          0 :   return total_size_;</span>
<span class="lineNum">     638 </span>            : }
<a name="639"><span class="lineNum">     639 </span>            : </a>
<span class="lineNum">     640 </span>            : template&lt;typename Element&gt;
<span class="lineNum">     641 </span><span class="lineNoCov">          0 : inline void RepeatedField&lt;Element&gt;::AddAlreadyReserved(const Element&amp; value) {</span>
<span class="lineNum">     642 </span>            :   GOOGLE_DCHECK_LT(size(), Capacity());
<span class="lineNum">     643 </span><span class="lineNoCov">          0 :   elements_[current_size_++] = value;</span>
<span class="lineNum">     644 </span><span class="lineNoCov">          0 : }</span>
<span class="lineNum">     645 </span>            : 
<span class="lineNum">     646 </span>            : template&lt;typename Element&gt;
<span class="lineNum">     647 </span>            : inline Element* RepeatedField&lt;Element&gt;::AddAlreadyReserved() {
<span class="lineNum">     648 </span>            :   GOOGLE_DCHECK_LT(size(), Capacity());
<span class="lineNum">     649 </span>            :   return &amp;elements_[current_size_++];
<span class="lineNum">     650 </span>            : }
<a name="651"><span class="lineNum">     651 </span>            : </a>
<span class="lineNum">     652 </span>            : template&lt;typename Element&gt;
<span class="lineNum">     653 </span><span class="lineNoCov">          0 : inline void RepeatedField&lt;Element&gt;::Resize(int new_size, const Element&amp; value) {</span>
<span class="lineNum">     654 </span>            :   GOOGLE_DCHECK_GE(new_size, 0);
<span class="lineNum">     655 </span><span class="lineNoCov">          0 :   if (new_size &gt; size()) {</span>
<span class="lineNum">     656 </span><span class="lineNoCov">          0 :     Reserve(new_size);</span>
<span class="lineNum">     657 </span><span class="lineNoCov">          0 :     std::fill(&amp;elements_[current_size_], &amp;elements_[new_size], value);</span>
<span class="lineNum">     658 </span>            :   }
<span class="lineNum">     659 </span><span class="lineNoCov">          0 :   current_size_ = new_size;</span>
<span class="lineNum">     660 </span><span class="lineNoCov">          0 : }</span>
<span class="lineNum">     661 </span>            : 
<span class="lineNum">     662 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     663 </span>            : inline const Element&amp; RepeatedField&lt;Element&gt;::Get(int index) const {
<span class="lineNum">     664 </span>            :   GOOGLE_DCHECK_GE(index, 0);
<span class="lineNum">     665 </span>            :   GOOGLE_DCHECK_LT(index, size());
<span class="lineNum">     666 </span><span class="lineCov">    1726649 :   return elements_[index];</span>
<span class="lineNum">     667 </span>            : }
<span class="lineNum">     668 </span>            : 
<span class="lineNum">     669 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     670 </span>            : inline Element* RepeatedField&lt;Element&gt;::Mutable(int index) {
<span class="lineNum">     671 </span>            :   GOOGLE_DCHECK_GE(index, 0);
<span class="lineNum">     672 </span>            :   GOOGLE_DCHECK_LT(index, size());
<span class="lineNum">     673 </span>            :   return elements_ + index;
<span class="lineNum">     674 </span>            : }
<span class="lineNum">     675 </span>            : 
<span class="lineNum">     676 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     677 </span>            : inline void RepeatedField&lt;Element&gt;::Set(int index, const Element&amp; value) {
<span class="lineNum">     678 </span>            :   GOOGLE_DCHECK_GE(index, 0);
<span class="lineNum">     679 </span>            :   GOOGLE_DCHECK_LT(index, size());
<span class="lineNum">     680 </span>            :   elements_[index] = value;
<span class="lineNum">     681 </span>            : }
<a name="682"><span class="lineNum">     682 </span>            : </a>
<span class="lineNum">     683 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     684 </span><span class="lineCov">    1724386 : inline void RepeatedField&lt;Element&gt;::Add(const Element&amp; value) {</span>
<span class="lineNum">     685 </span><span class="lineCov">    1724386 :   if (current_size_ == total_size_) Reserve(total_size_ + 1);</span>
<span class="lineNum">     686 </span><span class="lineCov">    1724386 :   elements_[current_size_++] = value;</span>
<span class="lineNum">     687 </span><span class="lineCov">    1724386 : }</span>
<span class="lineNum">     688 </span>            : 
<span class="lineNum">     689 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     690 </span>            : inline Element* RepeatedField&lt;Element&gt;::Add() {
<span class="lineNum">     691 </span>            :   if (current_size_ == total_size_) Reserve(total_size_ + 1);
<span class="lineNum">     692 </span>            :   return &amp;elements_[current_size_++];
<span class="lineNum">     693 </span>            : }
<span class="lineNum">     694 </span>            : 
<span class="lineNum">     695 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     696 </span>            : inline void RepeatedField&lt;Element&gt;::RemoveLast() {
<span class="lineNum">     697 </span>            :   GOOGLE_DCHECK_GT(current_size_, 0);
<span class="lineNum">     698 </span>            :   --current_size_;
<span class="lineNum">     699 </span>            : }
<span class="lineNum">     700 </span>            : 
<span class="lineNum">     701 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     702 </span>            : void RepeatedField&lt;Element&gt;::ExtractSubrange(
<span class="lineNum">     703 </span>            :     int start, int num, Element* elements) {
<span class="lineNum">     704 </span>            :   GOOGLE_DCHECK_GE(start, 0);
<span class="lineNum">     705 </span>            :   GOOGLE_DCHECK_GE(num, 0);
<span class="lineNum">     706 </span>            :   GOOGLE_DCHECK_LE(start + num, this-&gt;size());
<span class="lineNum">     707 </span>            : 
<span class="lineNum">     708 </span>            :   // Save the values of the removed elements if requested.
<span class="lineNum">     709 </span>            :   if (elements != NULL) {
<span class="lineNum">     710 </span>            :     for (int i = 0; i &lt; num; ++i)
<span class="lineNum">     711 </span>            :       elements[i] = this-&gt;Get(i + start);
<span class="lineNum">     712 </span>            :   }
<span class="lineNum">     713 </span>            : 
<span class="lineNum">     714 </span>            :   // Slide remaining elements down to fill the gap.
<span class="lineNum">     715 </span>            :   if (num &gt; 0) {
<span class="lineNum">     716 </span>            :     for (int i = start + num; i &lt; this-&gt;size(); ++i)
<span class="lineNum">     717 </span>            :       this-&gt;Set(i - num, this-&gt;Get(i));
<span class="lineNum">     718 </span>            :     this-&gt;Truncate(this-&gt;size() - num);
<span class="lineNum">     719 </span>            :   }
<span class="lineNum">     720 </span>            : }
<span class="lineNum">     721 </span>            : 
<span class="lineNum">     722 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     723 </span>            : inline void RepeatedField&lt;Element&gt;::Clear() {
<span class="lineNum">     724 </span><span class="lineCov">     850848 :   current_size_ = 0;</span>
<span class="lineNum">     725 </span>            : }
<a name="726"><span class="lineNum">     726 </span>            : </a>
<span class="lineNum">     727 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     728 </span><span class="lineCov">        467 : inline void RepeatedField&lt;Element&gt;::MergeFrom(const RepeatedField&amp; other) {</span>
<span class="lineNum">     729 </span><span class="lineCov">        467 :   GOOGLE_CHECK_NE(&amp;other, this);</span>
<span class="lineNum">     730 </span><span class="lineCov">        467 :   if (other.current_size_ != 0) {</span>
<span class="lineNum">     731 </span><span class="lineCov">         79 :     Reserve(current_size_ + other.current_size_);</span>
<span class="lineNum">     732 </span><span class="lineCov">         79 :     CopyArray(elements_ + current_size_, other.elements_, other.current_size_);</span>
<span class="lineNum">     733 </span><span class="lineCov">         79 :     current_size_ += other.current_size_;</span>
<span class="lineNum">     734 </span>            :   }
<span class="lineNum">     735 </span><span class="lineCov">        467 : }</span>
<span class="lineNum">     736 </span>            : 
<span class="lineNum">     737 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     738 </span>            : inline void RepeatedField&lt;Element&gt;::CopyFrom(const RepeatedField&amp; other) {
<span class="lineNum">     739 </span>            :   if (&amp;other == this) return;
<span class="lineNum">     740 </span>            :   Clear();
<span class="lineNum">     741 </span>            :   MergeFrom(other);
<span class="lineNum">     742 </span>            : }
<a name="743"><span class="lineNum">     743 </span>            : </a>
<span class="lineNum">     744 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     745 </span><span class="lineNoCov">          0 : inline Element* RepeatedField&lt;Element&gt;::mutable_data() {</span>
<span class="lineNum">     746 </span><span class="lineNoCov">          0 :   return elements_;</span>
<span class="lineNum">     747 </span>            : }
<span class="lineNum">     748 </span>            : 
<span class="lineNum">     749 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     750 </span>            : inline const Element* RepeatedField&lt;Element&gt;::data() const {
<span class="lineNum">     751 </span>            :   return elements_;
<span class="lineNum">     752 </span>            : }
<span class="lineNum">     753 </span>            : 
<span class="lineNum">     754 </span>            : 
<span class="lineNum">     755 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     756 </span>            : void RepeatedField&lt;Element&gt;::Swap(RepeatedField* other) {
<span class="lineNum">     757 </span><span class="lineNoCov">          0 :   if (this == other) return;</span>
<span class="lineNum">     758 </span><span class="lineNoCov">          0 :   Element* swap_elements     = elements_;</span>
<span class="lineNum">     759 </span><span class="lineNoCov">          0 :   int      swap_current_size = current_size_;</span>
<span class="lineNum">     760 </span><span class="lineNoCov">          0 :   int      swap_total_size   = total_size_;</span>
<span class="lineNum">     761 </span>            : 
<span class="lineNum">     762 </span><span class="lineNoCov">          0 :   elements_     = other-&gt;elements_;</span>
<span class="lineNum">     763 </span><span class="lineNoCov">          0 :   current_size_ = other-&gt;current_size_;</span>
<span class="lineNum">     764 </span><span class="lineNoCov">          0 :   total_size_   = other-&gt;total_size_;</span>
<span class="lineNum">     765 </span>            : 
<span class="lineNum">     766 </span><span class="lineNoCov">          0 :   other-&gt;elements_     = swap_elements;</span>
<span class="lineNum">     767 </span><span class="lineNoCov">          0 :   other-&gt;current_size_ = swap_current_size;</span>
<span class="lineNum">     768 </span><span class="lineNoCov">          0 :   other-&gt;total_size_   = swap_total_size;</span>
<span class="lineNum">     769 </span>            : }
<span class="lineNum">     770 </span>            : 
<span class="lineNum">     771 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     772 </span>            : void RepeatedField&lt;Element&gt;::SwapElements(int index1, int index2) {
<span class="lineNum">     773 </span>            :   using std::swap;  // enable ADL with fallback
<span class="lineNum">     774 </span>            :   swap(elements_[index1], elements_[index2]);
<span class="lineNum">     775 </span>            : }
<span class="lineNum">     776 </span>            : 
<span class="lineNum">     777 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     778 </span>            : inline typename RepeatedField&lt;Element&gt;::iterator
<span class="lineNum">     779 </span>            : RepeatedField&lt;Element&gt;::begin() {
<span class="lineNum">     780 </span>            :   return elements_;
<span class="lineNum">     781 </span>            : }
<span class="lineNum">     782 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     783 </span>            : inline typename RepeatedField&lt;Element&gt;::const_iterator
<span class="lineNum">     784 </span>            : RepeatedField&lt;Element&gt;::begin() const {
<span class="lineNum">     785 </span>            :   return elements_;
<span class="lineNum">     786 </span>            : }
<span class="lineNum">     787 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     788 </span>            : inline typename RepeatedField&lt;Element&gt;::iterator
<span class="lineNum">     789 </span>            : RepeatedField&lt;Element&gt;::end() {
<span class="lineNum">     790 </span>            :   return elements_ + current_size_;
<span class="lineNum">     791 </span>            : }
<span class="lineNum">     792 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     793 </span>            : inline typename RepeatedField&lt;Element&gt;::const_iterator
<span class="lineNum">     794 </span>            : RepeatedField&lt;Element&gt;::end() const {
<span class="lineNum">     795 </span><span class="lineNoCov">          0 :   return elements_ + current_size_;</span>
<span class="lineNum">     796 </span>            : }
<span class="lineNum">     797 </span>            : 
<span class="lineNum">     798 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     799 </span>            : inline int RepeatedField&lt;Element&gt;::SpaceUsedExcludingSelf() const {
<span class="lineNum">     800 </span>            :   return (elements_ != NULL) ? total_size_ * sizeof(elements_[0]) : 0;
<span class="lineNum">     801 </span>            : }
<span class="lineNum">     802 </span>            : 
<span class="lineNum">     803 </span>            : // Avoid inlining of Reserve(): new, copy, and delete[] lead to a significant
<a name="804"><span class="lineNum">     804 </span>            : // amount of code bloat.</a>
<span class="lineNum">     805 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     806 </span><span class="lineCov">        401 : void RepeatedField&lt;Element&gt;::Reserve(int new_size) {</span>
<span class="lineNum">     807 </span><span class="lineCov">        401 :   if (total_size_ &gt;= new_size) return;</span>
<span class="lineNum">     808 </span>            : 
<span class="lineNum">     809 </span><span class="lineCov">        397 :   Element* old_elements = elements_;</span>
<span class="lineNum">     810 </span><span class="lineCov">        397 :   total_size_ = max(google::protobuf::internal::kMinRepeatedFieldAllocationSize,</span>
<span class="lineNum">     811 </span><span class="lineCov">        794 :                     max(total_size_ * 2, new_size));</span>
<span class="lineNum">     812 </span><span class="lineCov">        397 :   elements_ = new Element[total_size_];</span>
<span class="lineNum">     813 </span><span class="lineCov">        397 :   if (old_elements != NULL) {</span>
<span class="lineNum">     814 </span><span class="lineCov">        256 :     MoveArray(elements_, old_elements, current_size_);</span>
<span class="lineNum">     815 </span><span class="lineCov">        256 :     delete [] old_elements;</span>
<span class="lineNum">     816 </span>            :   }
<span class="lineNum">     817 </span>            : }
<a name="818"><span class="lineNum">     818 </span>            : </a>
<span class="lineNum">     819 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     820 </span><span class="lineNoCov">          0 : inline void RepeatedField&lt;Element&gt;::Truncate(int new_size) {</span>
<span class="lineNum">     821 </span>            :   GOOGLE_DCHECK_LE(new_size, current_size_);
<span class="lineNum">     822 </span><span class="lineNoCov">          0 :   current_size_ = new_size;</span>
<span class="lineNum">     823 </span><span class="lineNoCov">          0 : }</span>
<span class="lineNum">     824 </span>            : 
<span class="lineNum">     825 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     826 </span>            : inline void RepeatedField&lt;Element&gt;::MoveArray(
<span class="lineNum">     827 </span>            :     Element to[], Element from[], int array_size) {
<span class="lineNum">     828 </span>            :   CopyArray(to, from, array_size);
<span class="lineNum">     829 </span>            : }
<span class="lineNum">     830 </span>            : 
<span class="lineNum">     831 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     832 </span>            : inline void RepeatedField&lt;Element&gt;::CopyArray(
<span class="lineNum">     833 </span>            :     Element to[], const Element from[], int array_size) {
<span class="lineNum">     834 </span>            :   internal::ElementCopier&lt;Element&gt;()(to, from, array_size);
<span class="lineNum">     835 </span>            : }
<span class="lineNum">     836 </span>            : 
<span class="lineNum">     837 </span>            : namespace internal {
<span class="lineNum">     838 </span>            : 
<span class="lineNum">     839 </span>            : template &lt;typename Element, bool HasTrivialCopy&gt;
<span class="lineNum">     840 </span>            : void ElementCopier&lt;Element, HasTrivialCopy&gt;::operator()(
<span class="lineNum">     841 </span>            :     Element to[], const Element from[], int array_size) {
<span class="lineNum">     842 </span>            :   std::copy(from, from + array_size, to);
<span class="lineNum">     843 </span>            : }
<span class="lineNum">     844 </span>            : 
<span class="lineNum">     845 </span>            : template &lt;typename Element&gt;
<span class="lineNum">     846 </span>            : struct ElementCopier&lt;Element, true&gt; {
<span class="lineNum">     847 </span>            :   void operator()(Element to[], const Element from[], int array_size) {
<span class="lineNum">     848 </span><span class="lineCov">        335 :     memcpy(to, from, array_size * sizeof(Element));</span>
<span class="lineNum">     849 </span>            :   }
<span class="lineNum">     850 </span>            : };
<span class="lineNum">     851 </span>            : 
<span class="lineNum">     852 </span>            : }  // namespace internal
<span class="lineNum">     853 </span>            : 
<span class="lineNum">     854 </span>            : 
<span class="lineNum">     855 </span>            : // -------------------------------------------------------------------
<span class="lineNum">     856 </span>            : 
<span class="lineNum">     857 </span>            : namespace internal {
<span class="lineNum">     858 </span>            : 
<span class="lineNum">     859 </span>            : inline RepeatedPtrFieldBase::RepeatedPtrFieldBase()
<span class="lineNum">     860 </span>            :   : elements_(NULL),
<span class="lineNum">     861 </span>            :     current_size_(0),
<span class="lineNum">     862 </span>            :     allocated_size_(0),
<span class="lineNum">     863 </span><span class="lineCov">        477 :     total_size_(kInitialSize) {</span>
<span class="lineNum">     864 </span>            : }
<a name="865"><span class="lineNum">     865 </span>            : </a>
<span class="lineNum">     866 </span>            : template &lt;typename TypeHandler&gt;
<span class="lineNum">     867 </span><span class="lineCov">        910 : void RepeatedPtrFieldBase::Destroy() {</span>
<span class="lineNum">     868 </span><span class="lineCov">       2054 :   for (int i = 0; i &lt; allocated_size_; i++) {</span>
<span class="lineNum">     869 </span><span class="lineCov">        572 :     TypeHandler::Delete(cast&lt;TypeHandler&gt;(elements_[i]));</span>
<span class="lineNum">     870 </span>            :   }
<span class="lineNum">     871 </span><span class="lineCov">        910 :   delete [] elements_;</span>
<span class="lineNum">     872 </span><span class="lineCov">        910 : }</span>
<span class="lineNum">     873 </span>            : 
<span class="lineNum">     874 </span>            : inline bool RepeatedPtrFieldBase::empty() const {
<span class="lineNum">     875 </span>            :   return current_size_ == 0;
<span class="lineNum">     876 </span>            : }
<span class="lineNum">     877 </span>            : 
<span class="lineNum">     878 </span>            : inline int RepeatedPtrFieldBase::size() const {
<span class="lineNum">     879 </span>            :   return current_size_;
<span class="lineNum">     880 </span>            : }
<span class="lineNum">     881 </span>            : 
<span class="lineNum">     882 </span>            : template &lt;typename TypeHandler&gt;
<span class="lineNum">     883 </span>            : inline const typename TypeHandler::Type&amp;
<span class="lineNum">     884 </span>            : RepeatedPtrFieldBase::Get(int index) const {
<span class="lineNum">     885 </span>            :   GOOGLE_DCHECK_GE(index, 0);
<span class="lineNum">     886 </span>            :   GOOGLE_DCHECK_LT(index, size());
<span class="lineNum">     887 </span><span class="lineCov">       1056 :   return *cast&lt;TypeHandler&gt;(elements_[index]);</span>
<span class="lineNum">     888 </span>            : }
<span class="lineNum">     889 </span>            : 
<span class="lineNum">     890 </span>            : 
<span class="lineNum">     891 </span>            : template &lt;typename TypeHandler&gt;
<span class="lineNum">     892 </span>            : inline typename TypeHandler::Type*
<span class="lineNum">     893 </span>            : RepeatedPtrFieldBase::Mutable(int index) {
<span class="lineNum">     894 </span>            :   GOOGLE_DCHECK_GE(index, 0);
<span class="lineNum">     895 </span>            :   GOOGLE_DCHECK_LT(index, size());
<span class="lineNum">     896 </span><span class="lineCov">          4 :   return cast&lt;TypeHandler&gt;(elements_[index]);</span>
<span class="lineNum">     897 </span>            : }
<a name="898"><span class="lineNum">     898 </span>            : </a>
<span class="lineNum">     899 </span>            : template &lt;typename TypeHandler&gt;
<span class="lineNum">     900 </span><span class="lineCov">        606 : inline typename TypeHandler::Type* RepeatedPtrFieldBase::Add() {</span>
<span class="lineNum">     901 </span><span class="lineCov">        606 :   if (current_size_ &lt; allocated_size_) {</span>
<span class="lineNum">     902 </span><span class="lineCov">        126 :     return cast&lt;TypeHandler&gt;(elements_[current_size_++]);</span>
<span class="lineNum">     903 </span>            :   }
<span class="lineNum">     904 </span><span class="lineCov">        480 :   if (allocated_size_ == total_size_) Reserve(total_size_ + 1);</span>
<span class="lineNum">     905 </span><span class="lineCov">        480 :   typename TypeHandler::Type* result = TypeHandler::New();</span>
<span class="lineNum">     906 </span><span class="lineCov">        480 :   ++allocated_size_;</span>
<span class="lineNum">     907 </span><span class="lineCov">        480 :   elements_[current_size_++] = result;</span>
<span class="lineNum">     908 </span><span class="lineCov">        480 :   return result;</span>
<span class="lineNum">     909 </span>            : }
<span class="lineNum">     910 </span>            : 
<span class="lineNum">     911 </span>            : template &lt;typename TypeHandler&gt;
<span class="lineNum">     912 </span>            : inline void RepeatedPtrFieldBase::RemoveLast() {
<span class="lineNum">     913 </span>            :   GOOGLE_DCHECK_GT(current_size_, 0);
<span class="lineNum">     914 </span>            :   TypeHandler::Clear(cast&lt;TypeHandler&gt;(elements_[--current_size_]));
<span class="lineNum">     915 </span>            : }
<span class="lineNum">     916 </span>            : 
<span class="lineNum">     917 </span>            : template &lt;typename TypeHandler&gt;
<span class="lineNum">     918 </span>            : void RepeatedPtrFieldBase::Clear() {
<span class="lineNum">     919 </span><span class="lineCov">       1128 :   for (int i = 0; i &lt; current_size_; i++) {</span>
<span class="lineNum">     920 </span><span class="lineCov">        171 :     TypeHandler::Clear(cast&lt;TypeHandler&gt;(elements_[i]));</span>
<span class="lineNum">     921 </span>            :   }
<span class="lineNum">     922 </span><span class="lineCov">        786 :   current_size_ = 0;</span>
<span class="lineNum">     923 </span>            : }
<a name="924"><span class="lineNum">     924 </span>            : </a>
<span class="lineNum">     925 </span>            : template &lt;typename TypeHandler&gt;
<span class="lineNum">     926 </span><span class="lineCov">        968 : inline void RepeatedPtrFieldBase::MergeFrom(const RepeatedPtrFieldBase&amp; other) {</span>
<span class="lineNum">     927 </span><span class="lineCov">        968 :   GOOGLE_CHECK_NE(&amp;other, this);</span>
<span class="lineNum">     928 </span><span class="lineCov">        968 :   Reserve(current_size_ + other.current_size_);</span>
<span class="lineNum">     929 </span><span class="lineCov">       1986 :   for (int i = 0; i &lt; other.current_size_; i++) {</span>
<span class="lineNum">     930 </span><span class="lineCov">        509 :     TypeHandler::Merge(other.template Get&lt;TypeHandler&gt;(i), Add&lt;TypeHandler&gt;());</span>
<span class="lineNum">     931 </span>            :   }
<span class="lineNum">     932 </span><span class="lineCov">        968 : }</span>
<span class="lineNum">     933 </span>            : 
<span class="lineNum">     934 </span>            : template &lt;typename TypeHandler&gt;
<span class="lineNum">     935 </span>            : inline void RepeatedPtrFieldBase::CopyFrom(const RepeatedPtrFieldBase&amp; other) {
<span class="lineNum">     936 </span>            :   if (&amp;other == this) return;
<span class="lineNum">     937 </span>            :   RepeatedPtrFieldBase::Clear&lt;TypeHandler&gt;();
<span class="lineNum">     938 </span>            :   RepeatedPtrFieldBase::MergeFrom&lt;TypeHandler&gt;(other);
<span class="lineNum">     939 </span>            : }
<span class="lineNum">     940 </span>            : 
<span class="lineNum">     941 </span>            : inline int RepeatedPtrFieldBase::Capacity() const {
<span class="lineNum">     942 </span>            :   return total_size_;
<span class="lineNum">     943 </span>            : }
<span class="lineNum">     944 </span>            : 
<span class="lineNum">     945 </span>            : inline void* const* RepeatedPtrFieldBase::raw_data() const {
<span class="lineNum">     946 </span>            :   return elements_;
<span class="lineNum">     947 </span>            : }
<span class="lineNum">     948 </span>            : 
<span class="lineNum">     949 </span>            : inline void** RepeatedPtrFieldBase::raw_mutable_data() const {
<span class="lineNum">     950 </span>            :   return elements_;
<span class="lineNum">     951 </span>            : }
<span class="lineNum">     952 </span>            : 
<span class="lineNum">     953 </span>            : template &lt;typename TypeHandler&gt;
<span class="lineNum">     954 </span>            : inline typename TypeHandler::Type** RepeatedPtrFieldBase::mutable_data() {
<span class="lineNum">     955 </span>            :   // TODO(kenton):  Breaks C++ aliasing rules.  We should probably remove this
<span class="lineNum">     956 </span>            :   //   method entirely.
<span class="lineNum">     957 </span>            :   return reinterpret_cast&lt;typename TypeHandler::Type**&gt;(elements_);
<span class="lineNum">     958 </span>            : }
<span class="lineNum">     959 </span>            : 
<span class="lineNum">     960 </span>            : template &lt;typename TypeHandler&gt;
<span class="lineNum">     961 </span>            : inline const typename TypeHandler::Type* const*
<span class="lineNum">     962 </span>            : RepeatedPtrFieldBase::data() const {
<span class="lineNum">     963 </span>            :   // TODO(kenton):  Breaks C++ aliasing rules.  We should probably remove this
<span class="lineNum">     964 </span>            :   //   method entirely.
<span class="lineNum">     965 </span>            :   return reinterpret_cast&lt;const typename TypeHandler::Type* const*&gt;(elements_);
<span class="lineNum">     966 </span>            : }
<span class="lineNum">     967 </span>            : 
<span class="lineNum">     968 </span>            : inline void RepeatedPtrFieldBase::SwapElements(int index1, int index2) {
<span class="lineNum">     969 </span>            :   using std::swap;  // enable ADL with fallback
<span class="lineNum">     970 </span>            :   swap(elements_[index1], elements_[index2]);
<span class="lineNum">     971 </span>            : }
<span class="lineNum">     972 </span>            : 
<span class="lineNum">     973 </span>            : template &lt;typename TypeHandler&gt;
<span class="lineNum">     974 </span>            : inline int RepeatedPtrFieldBase::SpaceUsedExcludingSelf() const {
<span class="lineNum">     975 </span>            :   int allocated_bytes =
<span class="lineNum">     976 </span>            :       (elements_ != NULL) ? total_size_ * sizeof(elements_[0]) : 0;
<span class="lineNum">     977 </span>            :   for (int i = 0; i &lt; allocated_size_; ++i) {
<span class="lineNum">     978 </span>            :     allocated_bytes += TypeHandler::SpaceUsed(*cast&lt;TypeHandler&gt;(elements_[i]));
<span class="lineNum">     979 </span>            :   }
<span class="lineNum">     980 </span>            :   return allocated_bytes;
<span class="lineNum">     981 </span>            : }
<span class="lineNum">     982 </span>            : 
<span class="lineNum">     983 </span>            : template &lt;typename TypeHandler&gt;
<span class="lineNum">     984 </span>            : inline typename TypeHandler::Type* RepeatedPtrFieldBase::AddFromCleared() {
<span class="lineNum">     985 </span>            :   if (current_size_ &lt; allocated_size_) {
<span class="lineNum">     986 </span>            :     return cast&lt;TypeHandler&gt;(elements_[current_size_++]);
<span class="lineNum">     987 </span>            :   } else {
<span class="lineNum">     988 </span>            :     return NULL;
<span class="lineNum">     989 </span>            :   }
<span class="lineNum">     990 </span>            : }
<span class="lineNum">     991 </span>            : 
<span class="lineNum">     992 </span>            : template &lt;typename TypeHandler&gt;
<span class="lineNum">     993 </span>            : void RepeatedPtrFieldBase::AddAllocated(
<span class="lineNum">     994 </span>            :     typename TypeHandler::Type* value) {
<span class="lineNum">     995 </span>            :   // Make room for the new pointer.
<span class="lineNum">     996 </span>            :   if (current_size_ == total_size_) {
<span class="lineNum">     997 </span>            :     // The array is completely full with no cleared objects, so grow it.
<span class="lineNum">     998 </span>            :     Reserve(total_size_ + 1);
<span class="lineNum">     999 </span>            :     ++allocated_size_;
<span class="lineNum">    1000 </span>            :   } else if (allocated_size_ == total_size_) {
<span class="lineNum">    1001 </span>            :     // There is no more space in the pointer array because it contains some
<span class="lineNum">    1002 </span>            :     // cleared objects awaiting reuse.  We don't want to grow the array in this
<span class="lineNum">    1003 </span>            :     // case because otherwise a loop calling AddAllocated() followed by Clear()
<span class="lineNum">    1004 </span>            :     // would leak memory.
<span class="lineNum">    1005 </span>            :     TypeHandler::Delete(cast&lt;TypeHandler&gt;(elements_[current_size_]));
<span class="lineNum">    1006 </span>            :   } else if (current_size_ &lt; allocated_size_) {
<span class="lineNum">    1007 </span>            :     // We have some cleared objects.  We don't care about their order, so we
<span class="lineNum">    1008 </span>            :     // can just move the first one to the end to make space.
<span class="lineNum">    1009 </span>            :     elements_[allocated_size_] = elements_[current_size_];
<span class="lineNum">    1010 </span>            :     ++allocated_size_;
<span class="lineNum">    1011 </span>            :   } else {
<span class="lineNum">    1012 </span>            :     // There are no cleared objects.
<span class="lineNum">    1013 </span>            :     ++allocated_size_;
<span class="lineNum">    1014 </span>            :   }
<span class="lineNum">    1015 </span>            : 
<span class="lineNum">    1016 </span>            :   elements_[current_size_++] = value;
<span class="lineNum">    1017 </span>            : }
<span class="lineNum">    1018 </span>            : 
<span class="lineNum">    1019 </span>            : template &lt;typename TypeHandler&gt;
<span class="lineNum">    1020 </span>            : inline typename TypeHandler::Type* RepeatedPtrFieldBase::ReleaseLast() {
<span class="lineNum">    1021 </span>            :   GOOGLE_DCHECK_GT(current_size_, 0);
<span class="lineNum">    1022 </span>            :   typename TypeHandler::Type* result =
<span class="lineNum">    1023 </span>            :       cast&lt;TypeHandler&gt;(elements_[--current_size_]);
<span class="lineNum">    1024 </span>            :   --allocated_size_;
<span class="lineNum">    1025 </span>            :   if (current_size_ &lt; allocated_size_) {
<span class="lineNum">    1026 </span>            :     // There are cleared elements on the end; replace the removed element
<span class="lineNum">    1027 </span>            :     // with the last allocated element.
<span class="lineNum">    1028 </span>            :     elements_[current_size_] = elements_[allocated_size_];
<span class="lineNum">    1029 </span>            :   }
<span class="lineNum">    1030 </span>            :   return result;
<span class="lineNum">    1031 </span>            : }
<span class="lineNum">    1032 </span>            : 
<span class="lineNum">    1033 </span>            : inline int RepeatedPtrFieldBase::ClearedCount() const {
<span class="lineNum">    1034 </span>            :   return allocated_size_ - current_size_;
<span class="lineNum">    1035 </span>            : }
<span class="lineNum">    1036 </span>            : 
<span class="lineNum">    1037 </span>            : template &lt;typename TypeHandler&gt;
<span class="lineNum">    1038 </span>            : inline void RepeatedPtrFieldBase::AddCleared(
<span class="lineNum">    1039 </span>            :     typename TypeHandler::Type* value) {
<span class="lineNum">    1040 </span>            :   if (allocated_size_ == total_size_) Reserve(total_size_ + 1);
<span class="lineNum">    1041 </span>            :   elements_[allocated_size_++] = value;
<span class="lineNum">    1042 </span>            : }
<span class="lineNum">    1043 </span>            : 
<span class="lineNum">    1044 </span>            : template &lt;typename TypeHandler&gt;
<span class="lineNum">    1045 </span>            : inline typename TypeHandler::Type* RepeatedPtrFieldBase::ReleaseCleared() {
<span class="lineNum">    1046 </span>            :   GOOGLE_DCHECK_GT(allocated_size_, current_size_);
<span class="lineNum">    1047 </span>            :   return cast&lt;TypeHandler&gt;(elements_[--allocated_size_]);
<span class="lineNum">    1048 </span>            : }
<span class="lineNum">    1049 </span>            : 
<span class="lineNum">    1050 </span>            : }  // namespace internal
<span class="lineNum">    1051 </span>            : 
<span class="lineNum">    1052 </span>            : // -------------------------------------------------------------------
<span class="lineNum">    1053 </span>            : 
<span class="lineNum">    1054 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1055 </span>            : class RepeatedPtrField&lt;Element&gt;::TypeHandler
<span class="lineNum">    1056 </span>            :     : public internal::GenericTypeHandler&lt;Element&gt; {
<span class="lineNum">    1057 </span>            : };
<span class="lineNum">    1058 </span>            : 
<span class="lineNum">    1059 </span>            : template &lt;&gt;
<span class="lineNum">    1060 </span>            : class RepeatedPtrField&lt;string&gt;::TypeHandler
<span class="lineNum">    1061 </span>            :     : public internal::StringTypeHandler {
<span class="lineNum">    1062 </span>            : };
<span class="lineNum">    1063 </span>            : 
<span class="lineNum">    1064 </span>            : 
<span class="lineNum">    1065 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1066 </span>            : inline RepeatedPtrField&lt;Element&gt;::RepeatedPtrField() {}
<span class="lineNum">    1067 </span>            : 
<span class="lineNum">    1068 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1069 </span>            : inline RepeatedPtrField&lt;Element&gt;::RepeatedPtrField(
<span class="lineNum">    1070 </span>            :     const RepeatedPtrField&amp; other)
<span class="lineNum">    1071 </span>            :     : RepeatedPtrFieldBase() {
<span class="lineNum">    1072 </span>            :   CopyFrom(other);
<span class="lineNum">    1073 </span>            : }
<span class="lineNum">    1074 </span>            : 
<span class="lineNum">    1075 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1076 </span>            : template &lt;typename Iter&gt;
<span class="lineNum">    1077 </span>            : inline RepeatedPtrField&lt;Element&gt;::RepeatedPtrField(
<span class="lineNum">    1078 </span>            :     Iter begin, const Iter&amp; end) {
<span class="lineNum">    1079 </span>            :   int reserve = internal::CalculateReserve(begin, end);
<span class="lineNum">    1080 </span>            :   if (reserve != -1) {
<span class="lineNum">    1081 </span>            :     Reserve(reserve);
<span class="lineNum">    1082 </span>            :   }
<span class="lineNum">    1083 </span>            :   for (; begin != end; ++begin) {
<span class="lineNum">    1084 </span>            :     *Add() = *begin;
<span class="lineNum">    1085 </span>            :   }
<span class="lineNum">    1086 </span>            : }
<span class="lineNum">    1087 </span>            : 
<span class="lineNum">    1088 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1089 </span>            : RepeatedPtrField&lt;Element&gt;::~RepeatedPtrField() {
<span class="lineNum">    1090 </span><span class="lineCov">        910 :   Destroy&lt;TypeHandler&gt;();</span>
<span class="lineNum">    1091 </span><span class="lineCov">        910 : }</span>
<span class="lineNum">    1092 </span>            : 
<span class="lineNum">    1093 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1094 </span>            : inline RepeatedPtrField&lt;Element&gt;&amp; RepeatedPtrField&lt;Element&gt;::operator=(
<span class="lineNum">    1095 </span>            :     const RepeatedPtrField&amp; other) {
<span class="lineNum">    1096 </span>            :   if (this != &amp;other)
<span class="lineNum">    1097 </span>            :     CopyFrom(other);
<span class="lineNum">    1098 </span>            :   return *this;
<span class="lineNum">    1099 </span>            : }
<span class="lineNum">    1100 </span>            : 
<span class="lineNum">    1101 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1102 </span>            : inline bool RepeatedPtrField&lt;Element&gt;::empty() const {
<span class="lineNum">    1103 </span>            :   return RepeatedPtrFieldBase::empty();
<span class="lineNum">    1104 </span>            : }
<span class="lineNum">    1105 </span>            : 
<span class="lineNum">    1106 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1107 </span>            : inline int RepeatedPtrField&lt;Element&gt;::size() const {
<span class="lineNum">    1108 </span>            :   return RepeatedPtrFieldBase::size();
<span class="lineNum">    1109 </span>            : }
<span class="lineNum">    1110 </span>            : 
<span class="lineNum">    1111 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1112 </span>            : inline const Element&amp; RepeatedPtrField&lt;Element&gt;::Get(int index) const {
<span class="lineNum">    1113 </span>            :   return RepeatedPtrFieldBase::Get&lt;TypeHandler&gt;(index);
<span class="lineNum">    1114 </span>            : }
<span class="lineNum">    1115 </span>            : 
<span class="lineNum">    1116 </span>            : 
<span class="lineNum">    1117 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1118 </span>            : inline Element* RepeatedPtrField&lt;Element&gt;::Mutable(int index) {
<span class="lineNum">    1119 </span>            :   return RepeatedPtrFieldBase::Mutable&lt;TypeHandler&gt;(index);
<span class="lineNum">    1120 </span>            : }
<span class="lineNum">    1121 </span>            : 
<span class="lineNum">    1122 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1123 </span>            : inline Element* RepeatedPtrField&lt;Element&gt;::Add() {
<span class="lineNum">    1124 </span><span class="lineCov">         97 :   return RepeatedPtrFieldBase::Add&lt;TypeHandler&gt;();</span>
<span class="lineNum">    1125 </span>            : }
<span class="lineNum">    1126 </span>            : 
<span class="lineNum">    1127 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1128 </span>            : inline void RepeatedPtrField&lt;Element&gt;::RemoveLast() {
<span class="lineNum">    1129 </span>            :   RepeatedPtrFieldBase::RemoveLast&lt;TypeHandler&gt;();
<span class="lineNum">    1130 </span>            : }
<span class="lineNum">    1131 </span>            : 
<span class="lineNum">    1132 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1133 </span>            : inline void RepeatedPtrField&lt;Element&gt;::DeleteSubrange(int start, int num) {
<span class="lineNum">    1134 </span>            :   GOOGLE_DCHECK_GE(start, 0);
<span class="lineNum">    1135 </span>            :   GOOGLE_DCHECK_GE(num, 0);
<span class="lineNum">    1136 </span>            :   GOOGLE_DCHECK_LE(start + num, size());
<span class="lineNum">    1137 </span>            :   for (int i = 0; i &lt; num; ++i)
<span class="lineNum">    1138 </span>            :     delete RepeatedPtrFieldBase::Mutable&lt;TypeHandler&gt;(start + i);
<span class="lineNum">    1139 </span>            :   ExtractSubrange(start, num, NULL);
<span class="lineNum">    1140 </span>            : }
<span class="lineNum">    1141 </span>            : 
<span class="lineNum">    1142 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1143 </span>            : inline void RepeatedPtrField&lt;Element&gt;::ExtractSubrange(
<span class="lineNum">    1144 </span>            :     int start, int num, Element** elements) {
<span class="lineNum">    1145 </span>            :   GOOGLE_DCHECK_GE(start, 0);
<span class="lineNum">    1146 </span>            :   GOOGLE_DCHECK_GE(num, 0);
<span class="lineNum">    1147 </span>            :   GOOGLE_DCHECK_LE(start + num, size());
<span class="lineNum">    1148 </span>            : 
<span class="lineNum">    1149 </span>            :   if (num &gt; 0) {
<span class="lineNum">    1150 </span>            :     // Save the values of the removed elements if requested.
<span class="lineNum">    1151 </span>            :     if (elements != NULL) {
<span class="lineNum">    1152 </span>            :       for (int i = 0; i &lt; num; ++i)
<span class="lineNum">    1153 </span>            :         elements[i] = RepeatedPtrFieldBase::Mutable&lt;TypeHandler&gt;(i + start);
<span class="lineNum">    1154 </span>            :     }
<span class="lineNum">    1155 </span>            :     CloseGap(start, num);
<span class="lineNum">    1156 </span>            :   }
<span class="lineNum">    1157 </span>            : }
<span class="lineNum">    1158 </span>            : 
<span class="lineNum">    1159 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1160 </span>            : inline void RepeatedPtrField&lt;Element&gt;::Clear() {
<span class="lineNum">    1161 </span>            :   RepeatedPtrFieldBase::Clear&lt;TypeHandler&gt;();
<span class="lineNum">    1162 </span>            : }
<span class="lineNum">    1163 </span>            : 
<span class="lineNum">    1164 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1165 </span>            : inline void RepeatedPtrField&lt;Element&gt;::MergeFrom(
<span class="lineNum">    1166 </span>            :     const RepeatedPtrField&amp; other) {
<span class="lineNum">    1167 </span><span class="lineCov">        490 :   RepeatedPtrFieldBase::MergeFrom&lt;TypeHandler&gt;(other);</span>
<span class="lineNum">    1168 </span>            : }
<span class="lineNum">    1169 </span>            : 
<span class="lineNum">    1170 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1171 </span>            : inline void RepeatedPtrField&lt;Element&gt;::CopyFrom(
<span class="lineNum">    1172 </span>            :     const RepeatedPtrField&amp; other) {
<span class="lineNum">    1173 </span>            :   RepeatedPtrFieldBase::CopyFrom&lt;TypeHandler&gt;(other);
<span class="lineNum">    1174 </span>            : }
<span class="lineNum">    1175 </span>            : 
<span class="lineNum">    1176 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1177 </span>            : inline Element** RepeatedPtrField&lt;Element&gt;::mutable_data() {
<span class="lineNum">    1178 </span>            :   return RepeatedPtrFieldBase::mutable_data&lt;TypeHandler&gt;();
<span class="lineNum">    1179 </span>            : }
<span class="lineNum">    1180 </span>            : 
<span class="lineNum">    1181 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1182 </span>            : inline const Element* const* RepeatedPtrField&lt;Element&gt;::data() const {
<span class="lineNum">    1183 </span>            :   return RepeatedPtrFieldBase::data&lt;TypeHandler&gt;();
<span class="lineNum">    1184 </span>            : }
<span class="lineNum">    1185 </span>            : 
<span class="lineNum">    1186 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1187 </span>            : void RepeatedPtrField&lt;Element&gt;::Swap(RepeatedPtrField* other) {
<span class="lineNum">    1188 </span><span class="lineNoCov">          0 :   RepeatedPtrFieldBase::Swap(other);</span>
<span class="lineNum">    1189 </span>            : }
<span class="lineNum">    1190 </span>            : 
<span class="lineNum">    1191 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1192 </span>            : void RepeatedPtrField&lt;Element&gt;::SwapElements(int index1, int index2) {
<span class="lineNum">    1193 </span>            :   RepeatedPtrFieldBase::SwapElements(index1, index2);
<span class="lineNum">    1194 </span>            : }
<span class="lineNum">    1195 </span>            : 
<span class="lineNum">    1196 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1197 </span>            : inline int RepeatedPtrField&lt;Element&gt;::SpaceUsedExcludingSelf() const {
<span class="lineNum">    1198 </span>            :   return RepeatedPtrFieldBase::SpaceUsedExcludingSelf&lt;TypeHandler&gt;();
<span class="lineNum">    1199 </span>            : }
<span class="lineNum">    1200 </span>            : 
<span class="lineNum">    1201 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1202 </span>            : inline void RepeatedPtrField&lt;Element&gt;::AddAllocated(Element* value) {
<span class="lineNum">    1203 </span>            :   RepeatedPtrFieldBase::AddAllocated&lt;TypeHandler&gt;(value);
<span class="lineNum">    1204 </span>            : }
<span class="lineNum">    1205 </span>            : 
<span class="lineNum">    1206 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1207 </span>            : inline Element* RepeatedPtrField&lt;Element&gt;::ReleaseLast() {
<span class="lineNum">    1208 </span>            :   return RepeatedPtrFieldBase::ReleaseLast&lt;TypeHandler&gt;();
<span class="lineNum">    1209 </span>            : }
<span class="lineNum">    1210 </span>            : 
<span class="lineNum">    1211 </span>            : 
<span class="lineNum">    1212 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1213 </span>            : inline int RepeatedPtrField&lt;Element&gt;::ClearedCount() const {
<span class="lineNum">    1214 </span>            :   return RepeatedPtrFieldBase::ClearedCount();
<span class="lineNum">    1215 </span>            : }
<span class="lineNum">    1216 </span>            : 
<span class="lineNum">    1217 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1218 </span>            : inline void RepeatedPtrField&lt;Element&gt;::AddCleared(Element* value) {
<span class="lineNum">    1219 </span>            :   return RepeatedPtrFieldBase::AddCleared&lt;TypeHandler&gt;(value);
<span class="lineNum">    1220 </span>            : }
<span class="lineNum">    1221 </span>            : 
<span class="lineNum">    1222 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1223 </span>            : inline Element* RepeatedPtrField&lt;Element&gt;::ReleaseCleared() {
<span class="lineNum">    1224 </span>            :   return RepeatedPtrFieldBase::ReleaseCleared&lt;TypeHandler&gt;();
<span class="lineNum">    1225 </span>            : }
<span class="lineNum">    1226 </span>            : 
<span class="lineNum">    1227 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1228 </span>            : inline void RepeatedPtrField&lt;Element&gt;::Reserve(int new_size) {
<span class="lineNum">    1229 </span>            :   return RepeatedPtrFieldBase::Reserve(new_size);
<span class="lineNum">    1230 </span>            : }
<span class="lineNum">    1231 </span>            : 
<span class="lineNum">    1232 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1233 </span>            : inline int RepeatedPtrField&lt;Element&gt;::Capacity() const {
<span class="lineNum">    1234 </span>            :   return RepeatedPtrFieldBase::Capacity();
<span class="lineNum">    1235 </span>            : }
<span class="lineNum">    1236 </span>            : 
<span class="lineNum">    1237 </span>            : // -------------------------------------------------------------------
<span class="lineNum">    1238 </span>            : 
<span class="lineNum">    1239 </span>            : namespace internal {
<span class="lineNum">    1240 </span>            : 
<span class="lineNum">    1241 </span>            : // STL-like iterator implementation for RepeatedPtrField.  You should not
<span class="lineNum">    1242 </span>            : // refer to this class directly; use RepeatedPtrField&lt;T&gt;::iterator instead.
<span class="lineNum">    1243 </span>            : //
<span class="lineNum">    1244 </span>            : // The iterator for RepeatedPtrField&lt;T&gt;, RepeatedPtrIterator&lt;T&gt;, is
<span class="lineNum">    1245 </span>            : // very similar to iterator_ptr&lt;T**&gt; in util/gtl/iterator_adaptors.h,
<span class="lineNum">    1246 </span>            : // but adds random-access operators and is modified to wrap a void** base
<span class="lineNum">    1247 </span>            : // iterator (since RepeatedPtrField stores its array as a void* array and
<span class="lineNum">    1248 </span>            : // casting void** to T** would violate C++ aliasing rules).
<span class="lineNum">    1249 </span>            : //
<span class="lineNum">    1250 </span>            : // This code based on net/proto/proto-array-internal.h by Jeffrey Yasskin
<span class="lineNum">    1251 </span>            : // (jyasskin@google.com).
<span class="lineNum">    1252 </span>            : template&lt;typename Element&gt;
<span class="lineNum">    1253 </span>            : class RepeatedPtrIterator
<span class="lineNum">    1254 </span>            :     : public std::iterator&lt;
<span class="lineNum">    1255 </span>            :           std::random_access_iterator_tag, Element&gt; {
<span class="lineNum">    1256 </span>            :  public:
<span class="lineNum">    1257 </span>            :   typedef RepeatedPtrIterator&lt;Element&gt; iterator;
<span class="lineNum">    1258 </span>            :   typedef std::iterator&lt;
<span class="lineNum">    1259 </span>            :           std::random_access_iterator_tag, Element&gt; superclass;
<span class="lineNum">    1260 </span>            : 
<span class="lineNum">    1261 </span>            :   // Shadow the value_type in std::iterator&lt;&gt; because const_iterator::value_type
<span class="lineNum">    1262 </span>            :   // needs to be T, not const T.
<span class="lineNum">    1263 </span>            :   typedef typename remove_const&lt;Element&gt;::type value_type;
<span class="lineNum">    1264 </span>            : 
<span class="lineNum">    1265 </span>            :   // Let the compiler know that these are type names, so we don't have to
<span class="lineNum">    1266 </span>            :   // write &quot;typename&quot; in front of them everywhere.
<span class="lineNum">    1267 </span>            :   typedef typename superclass::reference reference;
<span class="lineNum">    1268 </span>            :   typedef typename superclass::pointer pointer;
<span class="lineNum">    1269 </span>            :   typedef typename superclass::difference_type difference_type;
<span class="lineNum">    1270 </span>            : 
<span class="lineNum">    1271 </span>            :   RepeatedPtrIterator() : it_(NULL) {}
<span class="lineNum">    1272 </span>            :   explicit RepeatedPtrIterator(void* const* it) : it_(it) {}
<span class="lineNum">    1273 </span>            : 
<span class="lineNum">    1274 </span>            :   // Allow &quot;upcasting&quot; from RepeatedPtrIterator&lt;T**&gt; to
<span class="lineNum">    1275 </span>            :   // RepeatedPtrIterator&lt;const T*const*&gt;.
<span class="lineNum">    1276 </span>            :   template&lt;typename OtherElement&gt;
<span class="lineNum">    1277 </span>            :   RepeatedPtrIterator(const RepeatedPtrIterator&lt;OtherElement&gt;&amp; other)
<span class="lineNum">    1278 </span>            :       : it_(other.it_) {
<span class="lineNum">    1279 </span>            :     // Force a compiler error if the other type is not convertible to ours.
<span class="lineNum">    1280 </span>            :     if (false) {
<span class="lineNum">    1281 </span>            :       implicit_cast&lt;Element*, OtherElement*&gt;(0);
<span class="lineNum">    1282 </span>            :     }
<span class="lineNum">    1283 </span>            :   }
<span class="lineNum">    1284 </span>            : 
<span class="lineNum">    1285 </span>            :   // dereferenceable
<span class="lineNum">    1286 </span>            :   reference operator*() const { return *reinterpret_cast&lt;Element*&gt;(*it_); }
<span class="lineNum">    1287 </span>            :   pointer   operator-&gt;() const { return &amp;(operator*()); }
<span class="lineNum">    1288 </span>            : 
<span class="lineNum">    1289 </span>            :   // {inc,dec}rementable
<span class="lineNum">    1290 </span>            :   iterator&amp; operator++() { ++it_; return *this; }
<span class="lineNum">    1291 </span>            :   iterator  operator++(int) { return iterator(it_++); }
<span class="lineNum">    1292 </span>            :   iterator&amp; operator--() { --it_; return *this; }
<span class="lineNum">    1293 </span>            :   iterator  operator--(int) { return iterator(it_--); }
<span class="lineNum">    1294 </span>            : 
<span class="lineNum">    1295 </span>            :   // equality_comparable
<span class="lineNum">    1296 </span>            :   bool operator==(const iterator&amp; x) const { return it_ == x.it_; }
<span class="lineNum">    1297 </span>            :   bool operator!=(const iterator&amp; x) const { return it_ != x.it_; }
<span class="lineNum">    1298 </span>            : 
<span class="lineNum">    1299 </span>            :   // less_than_comparable
<span class="lineNum">    1300 </span>            :   bool operator&lt;(const iterator&amp; x) const { return it_ &lt; x.it_; }
<span class="lineNum">    1301 </span>            :   bool operator&lt;=(const iterator&amp; x) const { return it_ &lt;= x.it_; }
<span class="lineNum">    1302 </span>            :   bool operator&gt;(const iterator&amp; x) const { return it_ &gt; x.it_; }
<span class="lineNum">    1303 </span>            :   bool operator&gt;=(const iterator&amp; x) const { return it_ &gt;= x.it_; }
<span class="lineNum">    1304 </span>            : 
<span class="lineNum">    1305 </span>            :   // addable, subtractable
<span class="lineNum">    1306 </span>            :   iterator&amp; operator+=(difference_type d) {
<span class="lineNum">    1307 </span>            :     it_ += d;
<span class="lineNum">    1308 </span>            :     return *this;
<span class="lineNum">    1309 </span>            :   }
<span class="lineNum">    1310 </span>            :   friend iterator operator+(iterator it, difference_type d) {
<span class="lineNum">    1311 </span>            :     it += d;
<span class="lineNum">    1312 </span>            :     return it;
<span class="lineNum">    1313 </span>            :   }
<span class="lineNum">    1314 </span>            :   friend iterator operator+(difference_type d, iterator it) {
<span class="lineNum">    1315 </span>            :     it += d;
<span class="lineNum">    1316 </span>            :     return it;
<span class="lineNum">    1317 </span>            :   }
<span class="lineNum">    1318 </span>            :   iterator&amp; operator-=(difference_type d) {
<span class="lineNum">    1319 </span>            :     it_ -= d;
<span class="lineNum">    1320 </span>            :     return *this;
<span class="lineNum">    1321 </span>            :   }
<span class="lineNum">    1322 </span>            :   friend iterator operator-(iterator it, difference_type d) {
<span class="lineNum">    1323 </span>            :     it -= d;
<span class="lineNum">    1324 </span>            :     return it;
<span class="lineNum">    1325 </span>            :   }
<span class="lineNum">    1326 </span>            : 
<span class="lineNum">    1327 </span>            :   // indexable
<span class="lineNum">    1328 </span>            :   reference operator[](difference_type d) const { return *(*this + d); }
<span class="lineNum">    1329 </span>            : 
<span class="lineNum">    1330 </span>            :   // random access iterator
<span class="lineNum">    1331 </span>            :   difference_type operator-(const iterator&amp; x) const { return it_ - x.it_; }
<span class="lineNum">    1332 </span>            : 
<span class="lineNum">    1333 </span>            :  private:
<span class="lineNum">    1334 </span>            :   template&lt;typename OtherElement&gt;
<span class="lineNum">    1335 </span>            :   friend class RepeatedPtrIterator;
<span class="lineNum">    1336 </span>            : 
<span class="lineNum">    1337 </span>            :   // The internal iterator.
<span class="lineNum">    1338 </span>            :   void* const* it_;
<span class="lineNum">    1339 </span>            : };
<span class="lineNum">    1340 </span>            : 
<span class="lineNum">    1341 </span>            : // Provide an iterator that operates on pointers to the underlying objects
<span class="lineNum">    1342 </span>            : // rather than the objects themselves as RepeatedPtrIterator does.
<span class="lineNum">    1343 </span>            : // Consider using this when working with stl algorithms that change
<span class="lineNum">    1344 </span>            : // the array.
<span class="lineNum">    1345 </span>            : // The VoidPtr template parameter holds the type-agnostic pointer value
<span class="lineNum">    1346 </span>            : // referenced by the iterator.  It should either be &quot;void *&quot; for a mutable
<span class="lineNum">    1347 </span>            : // iterator, or &quot;const void *&quot; for a constant iterator.
<span class="lineNum">    1348 </span>            : template&lt;typename Element, typename VoidPtr&gt;
<span class="lineNum">    1349 </span>            : class RepeatedPtrOverPtrsIterator
<span class="lineNum">    1350 </span>            :     : public std::iterator&lt;std::random_access_iterator_tag, Element*&gt; {
<span class="lineNum">    1351 </span>            :  public:
<span class="lineNum">    1352 </span>            :   typedef RepeatedPtrOverPtrsIterator&lt;Element, VoidPtr&gt; iterator;
<span class="lineNum">    1353 </span>            :   typedef std::iterator&lt;
<span class="lineNum">    1354 </span>            :           std::random_access_iterator_tag, Element*&gt; superclass;
<span class="lineNum">    1355 </span>            : 
<span class="lineNum">    1356 </span>            :   // Shadow the value_type in std::iterator&lt;&gt; because const_iterator::value_type
<span class="lineNum">    1357 </span>            :   // needs to be T, not const T.
<span class="lineNum">    1358 </span>            :   typedef typename remove_const&lt;Element*&gt;::type value_type;
<span class="lineNum">    1359 </span>            : 
<span class="lineNum">    1360 </span>            :   // Let the compiler know that these are type names, so we don't have to
<span class="lineNum">    1361 </span>            :   // write &quot;typename&quot; in front of them everywhere.
<span class="lineNum">    1362 </span>            :   typedef typename superclass::reference reference;
<span class="lineNum">    1363 </span>            :   typedef typename superclass::pointer pointer;
<span class="lineNum">    1364 </span>            :   typedef typename superclass::difference_type difference_type;
<span class="lineNum">    1365 </span>            : 
<span class="lineNum">    1366 </span>            :   RepeatedPtrOverPtrsIterator() : it_(NULL) {}
<span class="lineNum">    1367 </span>            :   explicit RepeatedPtrOverPtrsIterator(VoidPtr* it) : it_(it) {}
<span class="lineNum">    1368 </span>            : 
<span class="lineNum">    1369 </span>            :   // dereferenceable
<span class="lineNum">    1370 </span>            :   reference operator*() const { return *reinterpret_cast&lt;Element**&gt;(it_); }
<span class="lineNum">    1371 </span>            :   pointer   operator-&gt;() const { return &amp;(operator*()); }
<span class="lineNum">    1372 </span>            : 
<span class="lineNum">    1373 </span>            :   // {inc,dec}rementable
<span class="lineNum">    1374 </span>            :   iterator&amp; operator++() { ++it_; return *this; }
<span class="lineNum">    1375 </span>            :   iterator  operator++(int) { return iterator(it_++); }
<span class="lineNum">    1376 </span>            :   iterator&amp; operator--() { --it_; return *this; }
<span class="lineNum">    1377 </span>            :   iterator  operator--(int) { return iterator(it_--); }
<span class="lineNum">    1378 </span>            : 
<span class="lineNum">    1379 </span>            :   // equality_comparable
<span class="lineNum">    1380 </span>            :   bool operator==(const iterator&amp; x) const { return it_ == x.it_; }
<span class="lineNum">    1381 </span>            :   bool operator!=(const iterator&amp; x) const { return it_ != x.it_; }
<span class="lineNum">    1382 </span>            : 
<span class="lineNum">    1383 </span>            :   // less_than_comparable
<span class="lineNum">    1384 </span>            :   bool operator&lt;(const iterator&amp; x) const { return it_ &lt; x.it_; }
<span class="lineNum">    1385 </span>            :   bool operator&lt;=(const iterator&amp; x) const { return it_ &lt;= x.it_; }
<span class="lineNum">    1386 </span>            :   bool operator&gt;(const iterator&amp; x) const { return it_ &gt; x.it_; }
<span class="lineNum">    1387 </span>            :   bool operator&gt;=(const iterator&amp; x) const { return it_ &gt;= x.it_; }
<span class="lineNum">    1388 </span>            : 
<span class="lineNum">    1389 </span>            :   // addable, subtractable
<span class="lineNum">    1390 </span>            :   iterator&amp; operator+=(difference_type d) {
<span class="lineNum">    1391 </span>            :     it_ += d;
<span class="lineNum">    1392 </span>            :     return *this;
<span class="lineNum">    1393 </span>            :   }
<span class="lineNum">    1394 </span>            :   friend iterator operator+(iterator it, difference_type d) {
<span class="lineNum">    1395 </span>            :     it += d;
<span class="lineNum">    1396 </span>            :     return it;
<span class="lineNum">    1397 </span>            :   }
<span class="lineNum">    1398 </span>            :   friend iterator operator+(difference_type d, iterator it) {
<span class="lineNum">    1399 </span>            :     it += d;
<span class="lineNum">    1400 </span>            :     return it;
<span class="lineNum">    1401 </span>            :   }
<span class="lineNum">    1402 </span>            :   iterator&amp; operator-=(difference_type d) {
<span class="lineNum">    1403 </span>            :     it_ -= d;
<span class="lineNum">    1404 </span>            :     return *this;
<span class="lineNum">    1405 </span>            :   }
<span class="lineNum">    1406 </span>            :   friend iterator operator-(iterator it, difference_type d) {
<span class="lineNum">    1407 </span>            :     it -= d;
<span class="lineNum">    1408 </span>            :     return it;
<span class="lineNum">    1409 </span>            :   }
<span class="lineNum">    1410 </span>            : 
<span class="lineNum">    1411 </span>            :   // indexable
<span class="lineNum">    1412 </span>            :   reference operator[](difference_type d) const { return *(*this + d); }
<span class="lineNum">    1413 </span>            : 
<span class="lineNum">    1414 </span>            :   // random access iterator
<span class="lineNum">    1415 </span>            :   difference_type operator-(const iterator&amp; x) const { return it_ - x.it_; }
<span class="lineNum">    1416 </span>            : 
<span class="lineNum">    1417 </span>            :  private:
<span class="lineNum">    1418 </span>            :   template&lt;typename OtherElement&gt;
<span class="lineNum">    1419 </span>            :   friend class RepeatedPtrIterator;
<span class="lineNum">    1420 </span>            : 
<span class="lineNum">    1421 </span>            :   // The internal iterator.
<span class="lineNum">    1422 </span>            :   VoidPtr* it_;
<span class="lineNum">    1423 </span>            : };
<span class="lineNum">    1424 </span>            : 
<span class="lineNum">    1425 </span>            : }  // namespace internal
<span class="lineNum">    1426 </span>            : 
<span class="lineNum">    1427 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1428 </span>            : inline typename RepeatedPtrField&lt;Element&gt;::iterator
<span class="lineNum">    1429 </span>            : RepeatedPtrField&lt;Element&gt;::begin() {
<span class="lineNum">    1430 </span>            :   return iterator(raw_data());
<span class="lineNum">    1431 </span>            : }
<span class="lineNum">    1432 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1433 </span>            : inline typename RepeatedPtrField&lt;Element&gt;::const_iterator
<span class="lineNum">    1434 </span>            : RepeatedPtrField&lt;Element&gt;::begin() const {
<span class="lineNum">    1435 </span>            :   return iterator(raw_data());
<span class="lineNum">    1436 </span>            : }
<span class="lineNum">    1437 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1438 </span>            : inline typename RepeatedPtrField&lt;Element&gt;::iterator
<span class="lineNum">    1439 </span>            : RepeatedPtrField&lt;Element&gt;::end() {
<span class="lineNum">    1440 </span>            :   return iterator(raw_data() + size());
<span class="lineNum">    1441 </span>            : }
<span class="lineNum">    1442 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1443 </span>            : inline typename RepeatedPtrField&lt;Element&gt;::const_iterator
<span class="lineNum">    1444 </span>            : RepeatedPtrField&lt;Element&gt;::end() const {
<span class="lineNum">    1445 </span>            :   return iterator(raw_data() + size());
<span class="lineNum">    1446 </span>            : }
<span class="lineNum">    1447 </span>            : 
<span class="lineNum">    1448 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1449 </span>            : inline typename RepeatedPtrField&lt;Element&gt;::pointer_iterator
<span class="lineNum">    1450 </span>            : RepeatedPtrField&lt;Element&gt;::pointer_begin() {
<span class="lineNum">    1451 </span>            :   return pointer_iterator(raw_mutable_data());
<span class="lineNum">    1452 </span>            : }
<span class="lineNum">    1453 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1454 </span>            : inline typename RepeatedPtrField&lt;Element&gt;::const_pointer_iterator
<span class="lineNum">    1455 </span>            : RepeatedPtrField&lt;Element&gt;::pointer_begin() const {
<span class="lineNum">    1456 </span>            :   return const_pointer_iterator(const_cast&lt;const void**&gt;(raw_mutable_data()));
<span class="lineNum">    1457 </span>            : }
<span class="lineNum">    1458 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1459 </span>            : inline typename RepeatedPtrField&lt;Element&gt;::pointer_iterator
<span class="lineNum">    1460 </span>            : RepeatedPtrField&lt;Element&gt;::pointer_end() {
<span class="lineNum">    1461 </span>            :   return pointer_iterator(raw_mutable_data() + size());
<span class="lineNum">    1462 </span>            : }
<span class="lineNum">    1463 </span>            : template &lt;typename Element&gt;
<span class="lineNum">    1464 </span>            : inline typename RepeatedPtrField&lt;Element&gt;::const_pointer_iterator
<span class="lineNum">    1465 </span>            : RepeatedPtrField&lt;Element&gt;::pointer_end() const {
<span class="lineNum">    1466 </span>            :   return const_pointer_iterator(
<span class="lineNum">    1467 </span>            :       const_cast&lt;const void**&gt;(raw_mutable_data() + size()));
<span class="lineNum">    1468 </span>            : }
<span class="lineNum">    1469 </span>            : 
<span class="lineNum">    1470 </span>            : 
<span class="lineNum">    1471 </span>            : // Iterators and helper functions that follow the spirit of the STL
<span class="lineNum">    1472 </span>            : // std::back_insert_iterator and std::back_inserter but are tailor-made
<span class="lineNum">    1473 </span>            : // for RepeatedField and RepatedPtrField. Typical usage would be:
<span class="lineNum">    1474 </span>            : //
<span class="lineNum">    1475 </span>            : //   std::copy(some_sequence.begin(), some_sequence.end(),
<span class="lineNum">    1476 </span>            : //             google::protobuf::RepeatedFieldBackInserter(proto.mutable_sequence()));
<span class="lineNum">    1477 </span>            : //
<span class="lineNum">    1478 </span>            : // Ported by johannes from util/gtl/proto-array-iterators.h
<span class="lineNum">    1479 </span>            : 
<span class="lineNum">    1480 </span>            : namespace internal {
<span class="lineNum">    1481 </span>            : // A back inserter for RepeatedField objects.
<span class="lineNum">    1482 </span>            : template&lt;typename T&gt; class RepeatedFieldBackInsertIterator
<span class="lineNum">    1483 </span>            :     : public std::iterator&lt;std::output_iterator_tag, T&gt; {
<span class="lineNum">    1484 </span>            :  public:
<span class="lineNum">    1485 </span>            :   explicit RepeatedFieldBackInsertIterator(
<span class="lineNum">    1486 </span>            :       RepeatedField&lt;T&gt;* const mutable_field)
<span class="lineNum">    1487 </span>            :       : field_(mutable_field) {
<span class="lineNum">    1488 </span>            :   }
<span class="lineNum">    1489 </span>            :   RepeatedFieldBackInsertIterator&lt;T&gt;&amp; operator=(const T&amp; value) {
<span class="lineNum">    1490 </span>            :     field_-&gt;Add(value);
<span class="lineNum">    1491 </span>            :     return *this;
<span class="lineNum">    1492 </span>            :   }
<span class="lineNum">    1493 </span>            :   RepeatedFieldBackInsertIterator&lt;T&gt;&amp; operator*() {
<span class="lineNum">    1494 </span>            :     return *this;
<span class="lineNum">    1495 </span>            :   }
<span class="lineNum">    1496 </span>            :   RepeatedFieldBackInsertIterator&lt;T&gt;&amp; operator++() {
<span class="lineNum">    1497 </span>            :     return *this;
<span class="lineNum">    1498 </span>            :   }
<span class="lineNum">    1499 </span>            :   RepeatedFieldBackInsertIterator&lt;T&gt;&amp; operator++(int /* unused */) {
<span class="lineNum">    1500 </span>            :     return *this;
<span class="lineNum">    1501 </span>            :   }
<span class="lineNum">    1502 </span>            : 
<span class="lineNum">    1503 </span>            :  private:
<span class="lineNum">    1504 </span>            :   RepeatedField&lt;T&gt;* field_;
<span class="lineNum">    1505 </span>            : };
<span class="lineNum">    1506 </span>            : 
<span class="lineNum">    1507 </span>            : // A back inserter for RepeatedPtrField objects.
<span class="lineNum">    1508 </span>            : template&lt;typename T&gt; class RepeatedPtrFieldBackInsertIterator
<span class="lineNum">    1509 </span>            :     : public std::iterator&lt;std::output_iterator_tag, T&gt; {
<span class="lineNum">    1510 </span>            :  public:
<span class="lineNum">    1511 </span>            :   RepeatedPtrFieldBackInsertIterator(
<span class="lineNum">    1512 </span>            :       RepeatedPtrField&lt;T&gt;* const mutable_field)
<span class="lineNum">    1513 </span>            :       : field_(mutable_field) {
<span class="lineNum">    1514 </span>            :   }
<span class="lineNum">    1515 </span>            :   RepeatedPtrFieldBackInsertIterator&lt;T&gt;&amp; operator=(const T&amp; value) {
<span class="lineNum">    1516 </span>            :     *field_-&gt;Add() = value;
<span class="lineNum">    1517 </span>            :     return *this;
<span class="lineNum">    1518 </span>            :   }
<span class="lineNum">    1519 </span>            :   RepeatedPtrFieldBackInsertIterator&lt;T&gt;&amp; operator=(
<span class="lineNum">    1520 </span>            :       const T* const ptr_to_value) {
<span class="lineNum">    1521 </span>            :     *field_-&gt;Add() = *ptr_to_value;
<span class="lineNum">    1522 </span>            :     return *this;
<span class="lineNum">    1523 </span>            :   }
<span class="lineNum">    1524 </span>            :   RepeatedPtrFieldBackInsertIterator&lt;T&gt;&amp; operator*() {
<span class="lineNum">    1525 </span>            :     return *this;
<span class="lineNum">    1526 </span>            :   }
<span class="lineNum">    1527 </span>            :   RepeatedPtrFieldBackInsertIterator&lt;T&gt;&amp; operator++() {
<span class="lineNum">    1528 </span>            :     return *this;
<span class="lineNum">    1529 </span>            :   }
<span class="lineNum">    1530 </span>            :   RepeatedPtrFieldBackInsertIterator&lt;T&gt;&amp; operator++(int /* unused */) {
<span class="lineNum">    1531 </span>            :     return *this;
<span class="lineNum">    1532 </span>            :   }
<span class="lineNum">    1533 </span>            : 
<span class="lineNum">    1534 </span>            :  private:
<span class="lineNum">    1535 </span>            :   RepeatedPtrField&lt;T&gt;* field_;
<span class="lineNum">    1536 </span>            : };
<span class="lineNum">    1537 </span>            : 
<span class="lineNum">    1538 </span>            : // A back inserter for RepeatedPtrFields that inserts by transfering ownership
<span class="lineNum">    1539 </span>            : // of a pointer.
<span class="lineNum">    1540 </span>            : template&lt;typename T&gt; class AllocatedRepeatedPtrFieldBackInsertIterator
<span class="lineNum">    1541 </span>            :     : public std::iterator&lt;std::output_iterator_tag, T&gt; {
<span class="lineNum">    1542 </span>            :  public:
<span class="lineNum">    1543 </span>            :   explicit AllocatedRepeatedPtrFieldBackInsertIterator(
<span class="lineNum">    1544 </span>            :       RepeatedPtrField&lt;T&gt;* const mutable_field)
<span class="lineNum">    1545 </span>            :       : field_(mutable_field) {
<span class="lineNum">    1546 </span>            :   }
<span class="lineNum">    1547 </span>            :   AllocatedRepeatedPtrFieldBackInsertIterator&lt;T&gt;&amp; operator=(
<span class="lineNum">    1548 </span>            :       T* const ptr_to_value) {
<span class="lineNum">    1549 </span>            :     field_-&gt;AddAllocated(ptr_to_value);
<span class="lineNum">    1550 </span>            :     return *this;
<span class="lineNum">    1551 </span>            :   }
<span class="lineNum">    1552 </span>            :   AllocatedRepeatedPtrFieldBackInsertIterator&lt;T&gt;&amp; operator*() {
<span class="lineNum">    1553 </span>            :     return *this;
<span class="lineNum">    1554 </span>            :   }
<span class="lineNum">    1555 </span>            :   AllocatedRepeatedPtrFieldBackInsertIterator&lt;T&gt;&amp; operator++() {
<span class="lineNum">    1556 </span>            :     return *this;
<span class="lineNum">    1557 </span>            :   }
<span class="lineNum">    1558 </span>            :   AllocatedRepeatedPtrFieldBackInsertIterator&lt;T&gt;&amp; operator++(
<span class="lineNum">    1559 </span>            :       int /* unused */) {
<span class="lineNum">    1560 </span>            :     return *this;
<span class="lineNum">    1561 </span>            :   }
<span class="lineNum">    1562 </span>            : 
<span class="lineNum">    1563 </span>            :  private:
<span class="lineNum">    1564 </span>            :   RepeatedPtrField&lt;T&gt;* field_;
<span class="lineNum">    1565 </span>            : };
<span class="lineNum">    1566 </span>            : }  // namespace internal
<span class="lineNum">    1567 </span>            : 
<span class="lineNum">    1568 </span>            : // Provides a back insert iterator for RepeatedField instances,
<span class="lineNum">    1569 </span>            : // similar to std::back_inserter().
<span class="lineNum">    1570 </span>            : template&lt;typename T&gt; internal::RepeatedFieldBackInsertIterator&lt;T&gt;
<span class="lineNum">    1571 </span>            : RepeatedFieldBackInserter(RepeatedField&lt;T&gt;* const mutable_field) {
<span class="lineNum">    1572 </span>            :   return internal::RepeatedFieldBackInsertIterator&lt;T&gt;(mutable_field);
<span class="lineNum">    1573 </span>            : }
<span class="lineNum">    1574 </span>            : 
<span class="lineNum">    1575 </span>            : // Provides a back insert iterator for RepeatedPtrField instances,
<span class="lineNum">    1576 </span>            : // similar to std::back_inserter().
<span class="lineNum">    1577 </span>            : template&lt;typename T&gt; internal::RepeatedPtrFieldBackInsertIterator&lt;T&gt;
<span class="lineNum">    1578 </span>            : RepeatedPtrFieldBackInserter(RepeatedPtrField&lt;T&gt;* const mutable_field) {
<span class="lineNum">    1579 </span>            :   return internal::RepeatedPtrFieldBackInsertIterator&lt;T&gt;(mutable_field);
<span class="lineNum">    1580 </span>            : }
<span class="lineNum">    1581 </span>            : 
<span class="lineNum">    1582 </span>            : // Special back insert iterator for RepeatedPtrField instances, just in
<span class="lineNum">    1583 </span>            : // case someone wants to write generic template code that can access both
<span class="lineNum">    1584 </span>            : // RepeatedFields and RepeatedPtrFields using a common name.
<span class="lineNum">    1585 </span>            : template&lt;typename T&gt; internal::RepeatedPtrFieldBackInsertIterator&lt;T&gt;
<span class="lineNum">    1586 </span>            : RepeatedFieldBackInserter(RepeatedPtrField&lt;T&gt;* const mutable_field) {
<span class="lineNum">    1587 </span>            :   return internal::RepeatedPtrFieldBackInsertIterator&lt;T&gt;(mutable_field);
<span class="lineNum">    1588 </span>            : }
<span class="lineNum">    1589 </span>            : 
<span class="lineNum">    1590 </span>            : // Provides a back insert iterator for RepeatedPtrField instances
<span class="lineNum">    1591 </span>            : // similar to std::back_inserter() which transfers the ownership while
<span class="lineNum">    1592 </span>            : // copying elements.
<span class="lineNum">    1593 </span>            : template&lt;typename T&gt; internal::AllocatedRepeatedPtrFieldBackInsertIterator&lt;T&gt;
<span class="lineNum">    1594 </span>            : AllocatedRepeatedPtrFieldBackInserter(
<span class="lineNum">    1595 </span>            :     RepeatedPtrField&lt;T&gt;* const mutable_field) {
<span class="lineNum">    1596 </span>            :   return internal::AllocatedRepeatedPtrFieldBackInsertIterator&lt;T&gt;(
<span class="lineNum">    1597 </span>            :       mutable_field);
<span class="lineNum">    1598 </span>            : }
<span class="lineNum">    1599 </span>            : 
<span class="lineNum">    1600 </span>            : }  // namespace protobuf
<span class="lineNum">    1601 </span>            : 
<span class="lineNum">    1602 </span>            : }  // namespace google
<span class="lineNum">    1603 </span>            : #endif  // GOOGLE_PROTOBUF_REPEATED_FIELD_H__
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
